-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDIVISION.ASM
More file actions
142 lines (108 loc) · 1.89 KB
/
DIVISION.ASM
File metadata and controls
142 lines (108 loc) · 1.89 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
140
141
142
jmp start
dvs db 0
dvn db 0
quo db 0
rmd db 0
ms1 db 'Enter dividend: $'
ms2 db 'Enter divisor: $'
ms3 db 'Answer: $'
clf db 13,10,'$'
start:
; clear registers
call clear_r
call clear_v
; print message
lea dx,ms1
mov ah,9
int 21h
; accept dividend
mov ah,1
int 21h
; store dividend to dvn
sub al,30h
mov dvn,al
; print line
call n_line
; clear registers
call clear_r
; print message
lea dx,ms2
mov ah,9
int 21h
; accept divisor
mov ah,1
int 21h
; store divisor to dvs
sub al,30h
mov dvs,al
; print line
call n_line
call n_line
; clear registers
call clear_r
; perform division
mov al,dvn
mov bl,dvs
div bl
; store quotient and remainder
or al,30h
mov quo,al
or ah,30h
mov rmd,ah
; print result message
lea dx,ms3
mov ah,9
int 21h
; print quotient
mov dl,quo
mov ah,2
int 21h
; print dot
mov dl,'.'
mov ah,2
int 21h
; set loop counter
mov cx,5
; perform division
call pf_div
; stop program
int 20h
pf_div:
; clear registers except cx
xor ax,ax
xor bx,bx
xor dx,dx
; multiply remainder by 10
sub rmd,30h
mov al,rmd
mov bl,10
mul bl
; divide it by the divisor
mov bl,dvs
div bl
; store remainder to rmd
or ah,30h
mov rmd,ah
; print qoutient
or al,30h
mov dl,al
mov ah,2
int 21h
; loop until cx is 0
loop pf_div
ret
n_line:
lea dx,clf
mov ah,9
int 21h
ret
clear_r:
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
ret
clear_v:
mov ax,3
int 10h
ret