0

I'm currently learning assembly and I've created a program that converts 16bit decimal value to binary, but because of the method I've used it's reversed. Output is 00001 instead of 10000. Is there a simple way of reversing the output?

org 100h
section .text
;program

mov ax,60000 ;INPUT NUMBER
mov bx,2

conv:
xor dx,dx
div bx
add dl,48
push ax
mov ah,2
int 21h
pop ax
cmp ax,0
je end
loop conv

end:

mov eax,4c00h
int 21h

section .data
  • 3
    Don't use `div` for powers of two. Use shift and carry. That will produce digits in the right order. For other bases, yeah, you might have to reverse the digits e.g. by storing into a buffer back to front. – Jester Apr 11 '20 at 12:36
  • Similar to [How to convert a binary integer number to a hex string?](https://stackoverflow.com/q/53823756) - you can rotate to get bits in MSB-first printing order. Or go through FLAGS like [Convert Character to binary assembly language](https://stackoverflow.com/q/40769766) – Peter Cordes Apr 11 '20 at 12:54

0 Answers0