I plan to convert the X variable to decimal. I’m having a hard time using turbo assembler, can you give a hand?
code segment ;inicio de un segmento unico
assume cs:code,ds:code,ss:code
org 100h ;localidad de inicio del contador
main proc ;procedimiento principal
mov ax,cs
mov ds,ax ; INICIO
mov ax, x
mov ah,4ch ;comienzo del fin de programa
int 21h ;fin del programa
main endp
x dw 0A92FH
code ends ; fin del segmento de codigo
end main ;fin del ensamble
Thanks a lot
When converting numbers to a printable format it’s often easiest to start with the last digit.
Consider converting 123 to “123”, how would we get the last digit? It’s the remained when dividing by 10 (the base). So 123 % 10 gives us 3 and 123 / 10 = 12 conveniently gives us the correct number to work with in the next iteration. On x86 the “DIV” instruction is nice enough to give us both the quotient and remainder (in
axanddxrespectively). All that remains is to store printable characters in the string.Putting all this together you end up with something like the following (using nasm syntax):
This requires a working buffer (16 for the case when base = 2 and an extra byte for the NUL terminator):
Adding support for signed numbers is left as an exercise for the reader. Here is roughly the same routine adapted for 64-bit assembly.