On Mon, 22 Jun 2026, Paul Koning via cctalk wrote:
I also remember running into him late one night, in the middle of a debug session. I asked what he was working on. Answer "packed decimal exponentiation". My question "what is that used for?" Answer: "compound interest in COBOL programming".
Oh yeah.

That's what it is for


In beginning high level language programming classes (FORTRAN, BASIC, C), I often gave compound interest as an early exercise in loops (displaying each iteration, not exponential direct calculation of end result, not BCD)


But, I used BCD a little in my sales tax TSR.


And, I have often [mis]used x86 BCD instructions for display of numbers:

AAM as a substitute for dividing by 10 for 0-99 two decimal digit number in an 8 bit register,


and DAA in converting a single hexadecimal digit into ASCII numeral:  (notice 
ADC to avoid JMPs)
  AND AL, 0Fh
  DAA
  ADD AL, 0F0h
  ADC AL, 40h

or:
  AND AL, 0Fh
  ADD AL, 0
  ADC AL,28h
  DAA


That is extendable to full content (4 hex digits) of 16 bit AX register:
        PUSH    CX      ; in case CX is in use outside of this

        MOV CX, 0404h   ; CH and CL are independent; CL as a ROL loop, CH as a 
manual count down
  N1:   ROL AX, CL
        PUSH AX         ;gonna get stepped on in display output

        AND AL, 0Fh     ;disply single hexadecimal digit
        DAA
        ADD AL, 0F0h
        ADC AL, 40h

        MOV AH, 0Eh     ;displays char in AL at cursor position
        INT 10h         ;       or save registers and use DL, and INT21h display

        POP AX          ;bring it back after display
        DEC CH
        JNZ N1

        POP CX          ; put it back

Reply via email to