-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTWODIGIT.ASM
More file actions
139 lines (106 loc) · 1.87 KB
/
TWODIGIT.ASM
File metadata and controls
139 lines (106 loc) · 1.87 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
jmp start
n1 db 0
n2 db 0
rs db 0
qt db 0
rm db 0
m1 db 'Enter 1st value: $'
m2 db 'Enter 2nd value: $'
m3 db 'Sum is: $'
cr db 13,10,'$'
start:
; clear registers
call clear_r
call clear_v
; print first message
lea dx,m1
mov ah,9
int 21h
; get 1st input
mov ah,1
int 21h
; store to n1
sub al,30h
mov n1,al
; new line
call n_line
; print second message
lea dx,m2
mov ah,9
int 21h
; get 2nd input
mov ah,1
int 21h
; store to n2
sub al,30h
mov n2,al
; new line
call n_line
; clear registers
call clear_r
; compute sum
mov al,n1
mov bl,n2
add al,bl
; store sum in result variable
mov rs,al
; clear registers
call clear_r
; compare results
mov al,rs
mov bl,9
cmp al,bl
jg twodigit
; print sum message
lea dx,m3
mov ah,9
int 21h
; print results
or rs,30h
mov dl,rs
mov ah,2
int 21h
; stop program
int 20h
twodigit:
; clear registers
call clear_r
; divide result by 10
mov al,rs
mov bl,10
div bl
; move the results to the coresponding variables
mov qt,ah
mov rm,al
; convert qt and rm back to ascii
or qt,30h
or rm,30h
; print 3rd message
lea dx,m3
mov ah,9
int 21h
; print remainder as 1st digit
mov dl,rm
mov ah,2
int 21h
; print qoutient as 2nd digit
mov dl,qt
mov ah,2
int 21h
; stop program
int 20h
n_line:
lea dx,cr
mov ah,9
int 21h
ret
clear_r:
xor ax,ax
xor ax,ax
xor cx,cx
xor dx,dx
ret
clear_v:
mov ax,3
int 10h
ret