如下即可:
ORG 0H
MOV R0, #30H
ACALL ZI
SJMP $
-----------------------------------
ZI:
MOV B, #0 先用0当做最大值.
MOV R7, #16比较16次.
LOOP: MOV A, @R0 取来一个数字.
CJNE A, B, B1 比较.
B1: JC B2 有借位转移.
MOV B, A 够减则存到B中.
B2: INC R0 转到下一个.
DJNZ R7, LOOP 循环16遍.
RET
-----------------------------------
END
ORG 0000HMOV DPTR,#TABLE
MOV R2,A(暂存A中原来的参数)
MOVCA,@A+DPTR 到表头地址加A中的偏移量处取数
MOV R0,A(把取来的第一个数放在R0中)
XCH A,R2 (把原暂存的A值和和才取的数进行交换存贮)
INC A (因是二字节的这准备取下一个字节的数)
MOVCA,@A+DPTR
MOV R1,A(把取的第二个字放在的R1中)
SJMP $
ORG 2000H
TABLE: DW 0,1,4,9,16,25,36,49,64,81,100,121,144,169
DW
196,225,256,289,324,361,400,441,484,529,576,625,676,729,784,841,900
END
四个按键,定义如下:KEY1 BIT P3.0
KEY2 BIT P3.1
KEY3 BIT P3.2
KEY4 BIT P3.3
按键处理程序:
-----------------------------------
READ_KEY:
JBKEY1, K2
CALL DELAY
JBKEY1, K2
JNB KEY1, $
PUSH ACC
INC 75H
MOV A, 75H
CJNE A, #10, ZINT01
MOV 75H, #0
ZINT01:
POP ACC
JMP K_EXIT
---------------
K2: JBKEY2, K3
CALL DELAY
JBKEY2, K3
JNB KEY2, $
PUSH ACC
INC 76H
MOV A, 76H
CJNE A, #10, ZINT01
MOV 76H, #0
ZINT01:
POP ACC
JMP K_EXIT
---------------
K3: JBKEY3, K4
CALL DELAY
JBKEY3, K4
JNB KEY3, $
PUSH ACC
DEC 75H
MOV A, 75H
CJNE A, #255, ZINT03
MOV 75H, #9
ZINT03:
POP ACC
JMP K_EXIT
---------------
K4: JBKEY4, K_EXIT
CALL DELAY
JBKEY4, K_EXIT
JNB KEY4, $
PUSH ACC
DEC 76H
MOV A, 76H
CJNE A, #255, ZINT04
MOV 76H, #9
ZINT04:
POP ACC
K_EXIT:
RET
---------------
DELAY:
DJNZ R7, $
DJNZ R7, $
RET
-----------------------------------
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)