Using Intel x86 Assembly Language, I want to display these lines which is about adding 2 numbers:
Enter val1: 4
Enter val2: 3
RESULT: 7
I wrote these instructions to get the values from user and perform the operation:
;start
.model small
.stack 100h
.data
msg1 db 'enter val1: $'
msg2 db 'enter val2: $'
msg3 db 'result is: $'
val1 db ?
val2 db ?
result db ?
.code
mov ax,@data
mov ds,ax
;display msg1
lea dx, msg1
mov ah,09h
int 21h
;get input val1
mov ah, 1
int 21h
mov val1, al
;new line
mov dl, 0ah
int 21h
;display msg2
lea dx, msg2
mov ah,09h
int 21h
;get input val2
mov ah, 1
int 21h
mov val2, al
;new line
mov dl, 0ah
int 21h
;add process
mov al, val1
mov bl, val2
add al, bl
add al, 30h
mov result, al
;display msg3
lea dx, msg3
mov ah,09h
int 21h
;display result
mov ah, 2
mov dl, result
int 21h
;end
mov ah,4ch
int 21h
end
However, the output of RESULT
I got is a strange value and I'm not really sure what is my mistake, because when I run it for subtraction with changing the first add
instruction to sub
, it works well:
Enter val1: 4
Enter val2: 3
RESULT: ǔ
what is the mistake?