-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab03.asm
174 lines (155 loc) · 3.1 KB
/
lab03.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
STSEG SEGMENT PARA STACK "STACK"
DB 64 DUP ( "STACK" )
STSEG ENDS
DSEG SEGMENT PARA PUBLIC "DATA"
msg_x db 'input x: $'
msg_z db 'z = $'
z dw 0
x dw 0
DSEG ENDS
CODE SEGMENT PARA PUBLIC "CODE"
MAIN PROC FAR
ASSUME CS: CODE, DS: DSEG, SS:STSEG
push DS
XOR ax, ax
push ax
mov ax, DSEG
mov DS, ax
mov ah, 9
lea dx, msg_x
int 21h
call input_number
mov word [x], ax
cmp word [x], 5
jle less_equ_5
mov ax, 35
imul word [x]
imul word [x]
sub ax, 15
jmp endmath
less_equ_5: ; прыгаем сюда если число меньше или равно пяти
cmp word [x], 0
jle less_equ_0
mov ax, 10
mov bx, word [x]
idiv bx
jmp endmath
less_equ_0: ; прыгаем сюда если число меньше или равно нулю
mov ax, 215
sub ax, word [x]
endmath:
mov word[z], ax
mov ah, 09h
lea dx, msg_z
int 21h
mov ax, word [z]
call output_number ; выводим наш результат
mov ah, 4ch ; выход
int 21h
MAIN ENDP
input_number PROC
mov dx, 0
mov ax, 0
mov cx, 0
mov bx, 0
mov di, 1
start_read:
mov ah, 01h
int 21h
cmp al, 32
je end_read
cmp al, 10
je end_read
cmp al, 13
je end_read
cmp al, 45
jne not_minus
cmp dx, 0
jne read_number_err
mov di, -1
jmp start_read
not_minus:
cmp al, 48
jge num_greater_48
jmp read_number_err
num_greater_48:
cmp al, 57
jle num_less_57
jmp read_number_err
num_less_57:
sub al, 48
xor ch, ch
mov cl, al
mov ax, dx
mov bx, 10
imul bx
add ax, cx
mov dx, ax
jmp start_read
end_read:
mov ax, dx
imul di
ret
read_number_err:
mov ax, 0
ret
input_number ENDP
output_number PROC
push ax
push bx
push cx
push dx
push si
push di
mov dx, 0
mov bx, 10
mov cx, 0
cmp ax, 0
je out_null
cmp ax, 0
jg out_greater_null
push ax
push dx
mov dl, 45
mov ah, 2
int 21h
pop dx
pop ax
mov bx, -1
imul bx
mov bx, 10
out_greater_null:
cmp ax, 0
je end_output_number
mov dx, 0
idiv bx
add dx, 48
push dx
inc cx
jmp out_greater_null
end_output_number:
pop dx
mov ah, 2
int 21h
loop end_output_number
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
out_null:
mov dl, 48
mov ah, 2
int 21h
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
output_number ENDP
CODE ENDS
END MAIN