-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_2.asm
139 lines (114 loc) · 1.78 KB
/
6_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
137
138
139
NAME EX6_2
DATA SEGMENT
MSG0 DB 0DH, 0AH, '$'
MSG1 DB 'D/A A/D', 0DH, 0AH, '$'
MSG2 DB ' ', '$'
HEX DB '0123456789ABCDEF'
NUM DB 0
DATA ENDS
STACKS SEGMENT PARA STACK
DB 1024 DUP(?)
STACKS ENDS
; macro to print messages
PRINTMSG MACRO NUM
PUSH AX
PUSH DX
MOV AH,9
MOV DX,OFFSET MSG&NUM
INT 21H
POP DX
POP AX
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACKS
; delay
DELAY PROC NEAR
PUSH AX
MOV AX,0FFFFH
DELAY_1: DEC AX
JNZ DELAY_1
POP AX
RET
DELAY ENDP
; DISPLAY SINGLE NUMBER
DISPLAY_NUM16 PROC NEAR
PUSH SI
PUSH AX
PUSH DX
AND AX,00FFH
LEA SI,HEX
ADD SI,AX
MOV DL,[SI]
MOV AH,2
INT 21H
POP DX
POP AX
POP SI
RET
DISPLAY_NUM16 ENDP
; DISPLAY NUMBER
DISPLAY PROC NEAR
PUSH DX
PUSH CX
PUSH AX
MOV DL, AL
;display higher number
MOV CL, 4
SHR AL, CL
AND AL, 0FH
CALL DISPLAY_NUM16
;display lower number
MOV AL, DL
AND AL, 0FH
CALL DISPLAY_NUM16
POP AX
POP CX
POP DX
RET
DISPLAY ENDP
; Main
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
INPUT:
MOV AH,0 ; read keyboard
INT 16H
CMP AL,'C'
JZ TRANS
CMP AL,'c'
JZ TRANS
CMP AL,'E'
JZ QUIT
CMP AL,'e'
JZ QUIT
JMP INPUT
TRANS:
PRINTMSG 0
PRINTMSG 1
MOV CX,20
TRANS1:
; D/A
MOV AL,NUM
ADD AL,11H
MOV NUM,AL
CALL DISPLAY
PRINTMSG 2
MOV DX,280H
OUT DX,AL
CALL DELAY
; A/D
MOV DX,289H
OUT DX,AL
CALL DELAY
MOV DX,289H
IN AL,DX
CALL DISPLAY
PRINTMSG 0
LOOP TRANS1
JMP INPUT
QUIT:
MOV AH,4CH
INT 21H
CODE ENDS
END START