-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadd_two_8_bit_numbers.asm
111 lines (82 loc) · 1.79 KB
/
add_two_8_bit_numbers.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
DATA SEGMENT
MSG1 DB "Enter first number : $"
MSG2 DB "Enter second number : $"
MSG3 DB "Result is : $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA, CS:CODE
START: MOV AX,DATA
MOV DS,AX
;Print first message
LEA DX,MSG1
MOV AH,09H
INT 21H
;Read first digit of number 1
MOV AH,01H
INT 21H
SUB AL,30H
MOV BH,AL
;Read second digit of number 1
MOV AH,01H
INT 21H
SUB AL,30H
MOV BL,AL
;Print second Message
LEA DX,MSG2
MOV AH,09H
INT 21H
;Read first digit of number 2
MOV AH,01H
INT 21H
SUB AL,30H
MOV CH,AL
;Read second digit of number 2
MOV AH,01H
INT 21H
SUB AL,30H
MOV CL,AL
;Performing AL=BL+CL
ADD BL,CL
MOV AL,BL
;Splitting AL into AH & AL
MOV AH,00H
AAA
;Saving result of first addition to BL(temperory)
MOV BL,AL
;Performing AL=BH+CH+AH
MOV AL,AH
ADD AL,BH
ADD AL,CH
;Splitting result into AH & AL
MOV AH,00H
AAA
;CH=AH,CL=AL
MOV CH,AH
MOV CL,AL
;Print last message
LEA DX,MSG3
MOV AH,09H
INT 21H
;Converting result to ascii
ADD CH,30H
ADD CL,30H
ADD BL,30H
;Printing Result
;If first digit is zero skip it
CMP CH,30H
JE LB
MOV DL,CH
MOV AH,02H
INT 21H
LB:
MOV DL,CL
MOV AH,02H
INT 21H
MOV DL,BL
MOV AH,02H
INT 21H
;Closing
MOV AH,4CH
INT 21H
CODE ENDS
END START