Reputation: 11
When I input numbers on my 2 variables I think it doesn't read it, so mov
has 0 value.
No problem compiling.
Here's my code:
include 'emu8086.inc'
org 100h
define_print_string
define_scan_num
define_print_num
define_print_num_uns
define_clear_screen
.model small
.data
;data
a db "oops",0
b db 0dh,0ah,"enter first number: ",0
c db 0dh,0ah,"the sum is :",0
d db 0dh,0ah,"Press 1 if adiition",0
e db 0dh,0ah,"Press 2 if subtraction",0
f db 0dh,0ah,"the diffirence is: ",0
g db 0dh,0ah,"enter second number: ",0
h db 0dh,0ah,"",0
num1 dw 0
num2 dw 0
result dw 0
;code
.code
start:
lea si,a
call print_string
lea si,d
call print_string
lea si,e
call print_string
mov ah,1
int 21h
cmp al,'1'
je addi
cmp al,'2'
je subt
cmp al,'?'
je start
;input number 1
proc enter1
lea si,b
call print_string
call scan_num
mov ax,num1
ret
endp enter1
;input number 2
proc enter2
lea si,g
call print_string
call scan_num
mov bx,num2
ret
endp enter2
addi:
call enter1
call enter2
add ax,bx
lea si,h
call print_string
lea si,c
call print_string
call print_num
subt:
end1:
end
Upvotes: 0
Views: 715
Reputation: 39676
call scan_num mov ax,num1
The scan_num macro leaves its result in the AX
register. Therefore you need to store AX
in the num1 variable using mov num1, ax
.
The same applies to entering the 2nd number.
cmp al,'?' je start ;input number 1 proc enter1
Consider what happens when the input is neither "1", nor "2", nor "?".
The code will fall through in the enter1 procedure!
Better write:
jmp start
;input number 1
proc enter1
You should calculate your sum as late as possible if you solely keep it in a register. You didn't use the result variable.
lea si,c
call print_string
mov ax, num1
add ax, num2
call print_num
Upvotes: 1