-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhex_ops.asm
89 lines (84 loc) · 1.38 KB
/
hex_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
; Reads a n-digit hexadecimal number where n = DL
; While reading it exits if Q or q is pressed
; Result : BX
; Modifies all registers
READ_HEX_DIGIT PROC NEAR
NUMBER:
READ
CMP AL,51H
JE ENDING
CMP AL,71H
JE ENDING
CMP AL,30H
JL NUMBER
CMP AL,39H
JG LETTER
PRINT AL
SUB AL,30H
RET
LETTER:
CMP AL,41H
JL NUMBER
CMP AL,46H
JG NUMBER
PRINT AL
SUB AL,37H
RET
READ_HEX_DIGIT ENDP
READ_N_DIGIT_HEX PROC NEAR
MOV BX,0
N_DIGIT_HEX:
MOV CL,4
ROL BX,CL
PUSH DX
CALL READ_HEX_DIGIT
POP DX
DEC DL
ADD BL,AL
CMP DL,00H
JG N_DIGIT_HEX
RET
READ_N_DIGIT_HEX ENDP
; Takes a number and prints it in hexadecimal form
; Modifies AX,BX
; Takes the initial number through CX
PRINT_HEX_DIGIT PROC NEAR
CMP AL,09H
JG LETTER
NUMBER:
ADD AL,30H
PRINT AL
RET
LETTER:
ADD AL,37H
PRINT AL
RET
PRINT_HEX_DIGIT ENDP
PRINT_HEX PROC NEAR
MOV BX,CX
AND CX,0F000H
ROR CH,1
ROR CH,1
ROR CH,1
ROR CH,1
MOV AL,CH
CALL PRINT_HEX_DIGIT
MOV CX,BX
AND CX,0F00H
MOV AL,CH
CALL PRINT_HEX_DIGIT
MOV CX,BX
AND CX,00F0H
ROR CL,1
ROR CL,1
ROR CL,1
ROR CL,1
MOV AL,CL
CALL PRINT_HEX_DIGIT
MOV CX,BX
AND CX,000FH
MOV AL,CL
CALL PRINT_HEX_DIGIT
MOV CX,BX
RET
PRINT_HEX ENDP