【单片机】请写一个超级简单的单片机汇编语言程序,万分感谢!!

2024-11-04 15:31:45
推荐回答(3个)
回答1:

;
ORG 0000H
AJMP START
ORG 0100H
START:
MOV 42H, #88H ;先设NA MOV A, 40H
CJNE A, 50H, LOOP1 ;NAH-NBH
SJMP NEXT ;相等则再去比较低八位
LOOP1:
JC LOOP ;不够减,就可以结束了
AJMP LOOP3 ;转

NEXT:
MOV A, 41H
CJNE A, 51H, LOOP2 ;NAL-NBL
LOOP2:
JC LOOP ;不够减,就可以结束了
LOOP3:
MOV 42H, #0FFH ;否则就是NA>=NB

LOOP:
AJMP LOOP

END

回答2:

ORG 0000H
AJMP START
ORG 0100H
START:
MOV A ,40H
CJNE A, 50H,LOOP1
AJMP LOOP2
LOOP1:
JC LOOP3
LOOP11:
MOV 42H, #0FFH
AJMP LOOP
LOOP2:
MOV A,41H
CJNE A,51H,LOOP21
LOOP21:
JC LOOP3
SJMP LOOP11
LOOP3 :
MOV 42H,#88H
LOOP:
AJMP LOOP
END

回答3:

NAH EQU 40H
NAL EQU 41H
NBH EQU 50H
NBL EQU 51H
ORG 0
LJMP START
ORG 100H
START:
MOV NAH,#21 ;测试数据
MOV NAL,#00
MOV NBH,#20
MOV NBL,#00
LCALL CPR16NANB ;主程序调用比较
SJMP $ ;查看输出结果42H
CPR16NANB:
MOV A, NAH
CJNE A, NBH, LOOP11
AJMP LOOP12 ;(相等跳转,判断低8位)
LOOP11:
JC LOOP3 ;(NAH 小于NBH跳转)
AJMP LOOP2 ;(NAH 大于NBH跳转)
LOOP12: MOV A, NAL
CJNE A, NBL, LOOP11
AJMP LOOP2 ;(两者完全相等)
LOOP1:
JC LOOP3
LOOP2:
MOV 42H, #0FFH
AJMP LOOP
LOOP3 :
MOV 42H,#88H
LOOP:
RET
END