tags:

views:

142

answers:

2

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?

+1  A: 

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.

mrduclaw
How can I do it when int21 for reading characters puts it in an 8-bit register, and DIV only have 16-bit?
Algific
Well the register is actually 32-bits, but you can just reference pieces of it by using the ax, al, ah (as opposed to the whole eax). So you should be fine if you fill the ax register with your 8-bit value.
mrduclaw
Ahhhh. Thank you.
Algific
Actualy the right answer is: movzx ax, dl. Only in that case the ah register will be set guarantee to 0.
GJ
A: 

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
Nick D