Displaying the 64-bit number in DI:SI:CX:BX
on 8086
Step 1. Calculating the digits
This requires using a chain of divisions starting at the Most Significant Word of the 64-bit number. The remainder of every division is re-used on the next division.
mov bp, 10 ;Constant divider 10
push bp ;Will signal the end of the PUSHed remainders
Next:
xor dx, dx
xchg ax, di ;Most Significant Word is in DI
div bp ;Divide Word3
xchg di, ax
xchg ax, si
div bp ;Divide Word2
xchg si, ax
xchg ax, cx
div bp ;Divide Word1
xchg cx, ax
xchg ax, bx ;Least Significant Word is in BX
div bp ;Divide Word0
mov bx, ax
push dx ;Every remainder is [0,9]
or ax, cx ;OR all quotients together
or ax, si
or ax, di
jnz Next ;Repeat while 64-bit number not zero
Please note that the xchg
instruction was used to reduce code size!
Step 2. Displaying the digits
To display the characters I'll presume this is running on DOS.
Should be real easy to adapt this to another OS...
pop dx ;This is digit for sure
More:
add dl, '0' ;Convert from remainder [0,9] to character ["0","9"]
mov ah, 02h
int 21h ;DisplayCharacter
pop dx
cmp dx, bp ;Repeat until it was the 'signal (bp=10)' that was POPed
jb More
ax
anddx
are 16-bit registers. Two of them can only form a 32-bit pseudo-register, not a 64-bit one. You needeax:edx
, which is only available from the 80386 onwards. – EOF