model small stack 128 data err db Not enough arguments errinp db Not n

 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
.model small
.stack 128
.data
err db 'Not enough arguments!$'
errinp db 'Not a number or sign!$'
.code
ax_out proc uses dx cx
.code
push ax
mov ah, 02h
mov cx, 12d
mainloop:
pop dx
push dx
shr dx,cl
and dl, 0Fh
cmp dl, 10d
jge add_37h
add dl, 30h
jmp print_4
add_37h:
add dl, 37h
print_4:
int 21h
sub cx,3
loop mainloop
pop dx
push dx
and dl, 0fh
cmp dl, 10d
jge add_37h_last
add dl, 30h
jmp print_last
add_37h_last:
add dl, 37h
print_last:
int 21h
pop ax
ret
ax_out endp
begin: mov ax, @data mov ds, ax mov cx, 0h input: mov ah, 01h int 21h cmp al, 39h jle numbers cmp al, 71h je exit cmp al, 70h je high_element jmp errorinp
numbers: cmp al, 30h jl sign sub ax, 130h push ax inc cx jmp input
exit: add cx, cx add sp, cx mov ax, 4c00h int 21h
high_element: cmp cx, 1 jl error pop ax push ax call ax_out jmp input
sign: cmp al, 2Bh je plus cmp al, 2Dh je minus jmp errorinp
plus: cmp cx, 02h jl error pop bx pop ax add ax, bx sub cx, 01h push ax call ax_out jmp input
minus: cmp cx, 02h jl error pop ax pop bx sub ax, bx sub cx, 01h push ax call ax_out jmp input
error: lea dx, err mov ah, 09h int 21h jmp input
errorinp: lea dx, errinp mov ah, 09h int 21h jmp input
end begin