Read a three digit number from keyboard and display the number on the screen.
readnum macro num ; defining macro to read a three digit number
mov ah, 01h ; to read third (from right to left) digit
int 21h
sub al, '0'
mov bh, 064h ; storing 100 or 064h into bh
mul bh ; here multiplier is in bh and multiplicand is in al and product is in ax (WORD)
mov ah, 00h
mov num, ax ; moving the content of al to memory location num
mov ah, 01h ; to read second digit
int 21h
sub al, '0'
mov bh, 0ah
mul bh
mov ah, 00h
add num, ax
mov ah, 01h
int 21h
sub al, '0'
mov ah, 00h
add num, ax
endm
printstring macro msg
mov ah, 09h
mov dx, offset msg
int 21h
endm
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'Enter a three digit number: ','$'
msg2 db cr, lf, 'You have entered: ','$'
num dw ?
temp db ?
result db 20 dup('$')
_DATA ends
_CODE segment
assume cs:_CODE, ds:_DATA
start: mov ax, _DATA
mov ds, ax
printstring msg1
readnum num
printstring msg2
printstring result
mov ah, 4ch
mov al, 00h
int 21h
_CODE ends
end start
What I would like to see is:
Enter a three digit number: 345
You have entered: 345