-
Notifications
You must be signed in to change notification settings - Fork 15
/
add_8b_2.asm
59 lines (47 loc) · 1.94 KB
/
add_8b_2.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
;program to add two 8b numbers
data segment
num1 db ?
num2 db ?
res db ?
msg1 db 10,13,"enter the first number: $"
msg2 db 10,13,"enter the second number: $"
msg3 db 10,13,"result of addition is: $"
data ends
assume cs:code,ds:data
code segment
start: mov ax,data
mov ds,ax ;initialize data segment
lea dx,msg1 ;load address of msg1 into dx
mov ah,9h ;interrupt to display contents of dx
int 21h
mov ah,1h ;read a character from console
int 21h
sub al,30h ;convert number into bcd from ascii form
mov num1,al ;store number as num1
lea dx,msg2 ;load address of msg2 into dx
mov ah,9h ;interrupt to display contents of dx
int 21h
mov ah,1h ;read a character from console
int 21h
sub al,30h ;convert number into bcd from ascii form
mov num2,al ;store number as num2
add al,num1 ;add num1 to num2
mov res,al ;store sum in res
mov ah,0 ;clear garabage value (ah to be used later)
aaa ;converts hex to bcd and stores values in ah and al
add ah,30h ;first digit converted into bcd
add al,30h ;second digit converted from ascii to bcd
mov bx,ax ;save value of ax into bx
lea dx,msg3 ;print ms3
mov ah,9h
int 21h
mov ah,2h ;print first digit
mov dl,bh
int 21h
mov ah,2 ;print second digit
mov dl,bl
int 21h
mov ah,4ch
int 21h
code ends
end start