-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdec_ops.asm
112 lines (108 loc) · 1.68 KB
/
dec_ops.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
; The functios below work definitely together
; We first call READ_DEC and after that PRODUCE_DEC
; All registers are modified
; The digits we can read are 4
; If we wish to read less than 4 digits we modify the instruction MOV CX,4
; which is located at the first line of each function
; Result : DX
; The result is the actual number we read
; The number we read is also printed
READ_DEC PROC NEAR
MOV CX,4
MOV BX,0
AGAIN:
READ
CMP AL,30H
JL AGAIN
CMP AL,39H
JG AGAIN
SAL BX,4
PUSH AX
PUSH DX
PRINT AL
POP DX
POP AX
MOV AH,0
SUB AL,30H
ADD BX,AX
LOOP AGAIN
RET
END1:
MOV DL,AL
PUSH DX
PRINT AL
POP DX
RET
READ_DEC ENDP
PRODUCE_DEC PROC NEAR
MOV CX,4
MOV DX,0
ADDR1:
MOV AX,10
MUL DX
MOV DX,AX
ROL BX,4
MOV AX,BX
AND AX,000FH
ADD DX,AX
LOOP ADDR1
MOV CX,DX
RET
PRODUCE_DEC ENDP
; Transforms to dec and prints
; Takes the number through register DX
; Modifies all registers
PRINT_DEC PROC NEAR
MOV BX,0
MOV CX,0
LOOP1:
SUB DX,2710H
CMP DX,0
JL EXIT1
INC BH
JMP LOOP1
EXIT1:
ADD BH,30H
ADD DX,2710H
LOOP2:
SUB DX,03E8H
CMP DX,0
JL EXIT2
INC BL
JMP LOOP2
EXIT2:
ADD BL,30H
ADD DX,03E8H
LOOP3:
SUB DX,64H
CMP DX,0
JL EXIT3
INC CH
JMP LOOP3
EXIT3:
ADD CH,30H
ADD DX,64H
LOOP4:
SUB DX,0AH
CMP DX,0
JL EXIT4
INC CL
JMP LOOP4
EXIT4:
ADD CL,30H
ADD DX,0AH
ADD DX,30H
CMP BH,30H
JE NOT_ALL
PUSH DX
PRINT BH
POP DX
NOT_ALL:
PUSH DX
PRINT BL
PRINT CH
PRINT CL
POP DX
PRINT DL
RET
PRINT_DEC ENDP