This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMINUS.ASM
83 lines (83 loc) · 1.59 KB
/
MINUS.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
ORG 0000H
;使用01位寄存器R0,R1,R3,将20H,10H开始的数码相减,结果存入20H
MINUS:
MOV RS1,#1B
MOV RS0,#0B
MOV R0,#20H ;十进制数存放地址初始化
MOV R1,#10H
MOV R3,#08H ;字节长度初始化
LCALL GETMAX
CLR C
MINUSLOOP: ;从40H开始循环遍历十进制数的各个数位
MOV A,@R0
MINUSCON:
SUBB A,@R1
JC MINUSFIX
MOV @R0,A ;暂存十进制数数位相加结果
;清空CY,为接下来的判断做准备
LJMP MINUSFIN
MINUSFIX:
ADD A,#10
MOV @R0,A
LJMP MINUSFIN
;SUBB A, #10H
;JNC MINUSFIX ;判断数位相加是否大于等于10,若条件满足则进位,否则清空CY标志位
;CLR C
;LJMP MINUSFIN
MINUSFIN:
INC R0 ;循环遍历
INC R1
DJNZ R3,MINUSLOOP
MOV A,R4
JZ MEM1
JNZ MEM2
MEM1:
MOV RS1,#0B
MOV RS0,#1B
MOV R0,#20H
MOV R1,#10H
LCALL MEMMOVE
SJMP $
MEM2:
MOV 17H,#17
SJMP $ ;程序结束
GETMAX:
MOV RS1,#1B
MOV RS0,#1B
MOV R0,#27H
MOV R1,#17H
MOV R2,#08H
GETLOOP:
MOV A,@R0
CLR C
SUBB A,@R1
JC GETFINAL
JNZ GET2
DEC R0
DEC R1
DJNZ R2,GETLOOP
LJMP GET2
GETFINAL:
MOV RS1,#1B
MOV RS0,#0B
MOV R0,#10H
MOV R1,#20H
MOV R4,#01H
RET
GET2:
MOV RS1,#1B
MOV RS0,#0B
MOV R0,#20H
MOV R1,#10H
MOV R4,#00H
RET
;MEMMOVE 将R0开头的数据移动到R1开始的存储单元,数据共8位
MEMMOVE:
MOV R2,#09H
MEMLOOP:
MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R2,MEMLOOP
RET