-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLB6.2.ASM
136 lines (97 loc) · 2.49 KB
/
LB6.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
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
;Äàëüíèé âûçîâ, ïåðåäà÷à ïåðåìåííûìè
Format MZ
entry Main:Start
segment DataSegment
strInput_1 db 'Enter a number_1: $'
strInput_2 db 'Enter a number_2: $'
strOutput db 'Result: $'
strNewLine db 13, 10, '$'
bufInput db 5, 0, 5 dup (?)
strNum_1 dw ?
StrNum_2 Dw ?
ResNum dw ?
segment Main
Start:
mov ax, DataSegment
mov ds, ax
mov ah, 09h
mov dx, strInput_1
int 21h
mov ah, 0ah
mov dx, bufInput
int 21h
mov ah, 09h
mov dx, strNewLine
int 21h
call far Procedures:StrToInt ;ax - ÷èñëî
mov [strNum_1], ax
call far Procedures:CalcNum_1
mov ah, 09h
mov dx, strInput_2
int 21h
mov ah, 0ah
mov dx, bufInput
int 21h
mov ah, 09h
mov dx, strNewLine
int 21h
call far Procedures:StrToInt
mov [StrNum_2], ax
call far Procedures:CalcNum_2
call far Procedures:CalcRes
mov ah, 02h
int 21h
retf
segment Procedures
StrToInt:
push bp
mov bp, sp
mov cl, [bufInput + 1]
mov ch, 0
mov si, 2
mov ax, 0
mov di, 10
.LoopLabel1:
mul di
mov bl, [bufInput + si]
sub bl, 48
mov bh, 0
add ax, bx
inc si
loop .LoopLabel1
mov sp, bp
pop bp
retf
CalcNum_1:
mov cx, [strNum_1]
mov ax, cx ;ïåðâûé ìíîæèòåëü â ax
mov bx, ax ;âòîðîé ìíîæèòåëü â bx
mul bx ; ax = ax * bx A^2
mov bx, cx
mul ebx
mov [strNum_1], ax
retf
CalcNum_2:
mov ax, [StrNum_2]
mov bx, ax
mul bx
mov [StrNum_2], ax
retf
CalcRes:
mov ax, [strNum_1]
mov bx, [StrNum_2]
sub ax, bx
mov [ResNum], ax
call intToStrAndDisp
retf
intToStrAndDisp:
aam
mov ax, [ResNum]
add ax, '00'
mov dl, ah
mov dh, al
mov ah, 02h
int 21h
mov dl, dh
int 21h
retf