Question

I have a number stored in dl, and I need this to work for numbers up to three digits? Here is the working code for digits 0-9.

WriteNumber:
;; print out number in dl
push ax
push dx
add dl,"0"
mov ah,02h ; printing one char
int 21h
pop dx
pop ax
ret

For example, for two digits. I could take dl/10. And then print out the result and the rest as to different chars. But I got an error, because the number needs to be in AX register for the DIV.

I need to do this:

mov ax,dl

But that won't work?

Was it helpful?

Solution

I don't think you'll be able to do

mov ax,dl

since ax and dl are different sizes. You should be able to do

mov ax, dx

or from GJ:

movzx ax, dl

And then just reference dl and al if you want just the last byte.

OTHER TIPS

I need to do this:

mov ax,dl

But that won't work?

mov will work if the registers have the same size, both 8bit or 16bit or 32bit.

Example:

mov EAX, EDX
; or
mov AX, DX
; or
mov AL, DL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top