-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise.asm
187 lines (156 loc) · 2.52 KB
/
exercise.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
175
176
177
178
179
180
181
182
183
184
185
186
187
;-----------------------------------------------------------------------------
XL equ 0x50 ; the lower byte of the input value
YH equ 0x52 ; high byte of the input value
YL equ 0x53 ; auxiliary value
Z equ 0x40 ; the lower byte of the input value
ZZ equ 0x41 ; high byte of the input value
;-----------------------------------------------------------------------------
cseg AT 0
ljmp Main
;-----------------------------------------------------------------------------
; The algorithm converts a binary value from an 8-bit A/D converter, where the reference voltage of which is 5 V.
;-----------------------------------------------------------------------------
Main:
mov XL, #0x3E ; input value
multiplication_16bit:
mov R1, #0x00
mov R2, #0x00
mov R3, XL
mov R4, #0x64
mov A, R3
mov B, R4
mul AB
mov 20h, A
mov 21h, B
mov A, R3
mov B, R2
mul AB
mov 22h, B
addc A, 21h
mov 21h, A
mov A, R1
mov B, R4
mul AB
addc A, 21h
mov 21h, A
mov A, B
addc A, 22h
mov 22h, A
mov A, R1
mov B, R2
mul AB
addc A, 22h
mov 22h, A
mov A, B
addc A, #00h
mov 23h, A
mov YL, 20h
mov YH, 21h
mov R6, #0
mov R7, #0
mov B, #16
mov R0, YL
mov R1, YH
mov R2, #33h
mov R3, #00h
divide_16bit:
clr C
mov A, R0
rlc A
mov R0, A
mov A, R1
rlc A
mov R1, A
mov A, R6
rlc A
mov R6, A
mov A, R7
rlc A
mov R7, A
mov A, R6
clr C
subb A, R2
mov DPL, A
mov A, R7
subb A, R3
mov DPH, A
cpl C
jnc divide_bit
mov R7, DPH
mov R6, DPL
divide_bit:
mov A, R4
rlc A
mov R4, A
mov A, R5
rlc A
mov R5, A
djnz B, divide_16bit
mov A, R5
mov R1, A
mov A, R4
mov R0, A
mov A, R7
mov R3, A
mov A, R6
mov R2, A
mov Z, R0 ; output data
mov ZZ, R1
convert_to_ASCII:
mov B, #10
mov A , Z
div AB
mov R1, B
mov B, #10
div AB
mov R2, B
mov R3, A
mov A, ZZ
cjne A, #00h, step_further
ljmp addition
step_further:
mov A, #6
add A,R1
mov B, #10
div AB
mov R1,B
add A, #5
add A, R2
mov B, #10
div AB
mov R2, B
add A, #2
add A, R3
mov B, #10
div AB
mov R3,B
add A,R4
mov R4,A
mov b, #10
mov A,R4
div AB
mov R4,B
mov R5,A
addition:
mov A, R5
add A, #30h
mov R5, A
mov A, R4
add A, #30h
mov R4, A
mov A, R3
add A, #30h
mov R3, A
mov A, R2
add A, #30h
mov R2, A
mov A, R1
add A, #30h
mov R1, A
insert_result:
mov 0x43, R1
mov 0x42, R2
mov 0x40, R3
mov 0x41, #2Eh
jmp $
END