8051单片机汇编程序请教
设有40个有符号数,连续存放在2000H为首地址的存储单元,试编程统计其中零,正数和负数的个数分别保存在R2,R3,R4中。
我的编程如下:
ORG 0100H
MOV A,#00H
MOV R2,A
MOV R3,A
MOV R4,A
MOV R6,A
MOV R5,#40
;CLR C
MOV DPTR,#TABLE
LOOP: MOVC A,@A+DPTR
CJNE A,#00H,CONT_P
INC R2
SJMP NEXT
CONT_P: JC CONT_N
INC R3
SJMP NEXT
CONT_N: INC R4
NEXT: INC DPTR
DJNZ R5, LOOP
MOV P0,R4
SJMP $
ORG 2000H
TABLE: DB 01H,15H,22H,0FFH,00H,02H,09H,0F9H,00H,00H
DB 01H,15H,22H,0FFH,00H,02H,09H,0F9H,00H,00H
DB 01H,15H,22H,0FFH,00H,02H,09H,0F9H,00H,00H
DB 02H,05H,00H,0FFH,26H,34H,00H,00H,00H,00H
END
; 实际个数 保存单元 统计个数
;零个数 14 R2 21
;正数个数 19 R3 19
;负数个数: 7 R4 0
其实是零和负数没有分开统计,请高手指教一下,谢谢!
于是我改写成的如下,好象也有些问题:
ORG 0100H
MOV A,#00H
MOV R2,A
MOV R3,A
MOV R4,A
MOV R6,A
MOV R5,#40
;CLR C
MOV DPTR,#TABLE
LOOP: MOVC A,@A+DPTR
JNZ CONT_P
INC R2
SJMP NEXT
CONT_P: JB ACC.7,CONT_N
INC R3
SJMP NEXT
CONT_N: INC R4
NEXT: INC DPTR
DJNZ R5, LOOP
MOV P0,R2
SJMP $
ORG 2000H
TABLE: DB 01H,15H,22H,0FFH,00H,02H,09H,0F9H,00H,00H
DB 01H,15H,22H,0FFH,00H,02H,09H,0F9H,00H,00H
DB 01H,15H,22H,0FFH,00H,02H,09H,0F9H,00H,00H
DB 02H,05H,00H,0FFH,26H,34H,00H,00H,00H,00H
END
初学汇编,水平很菜,多多指点!如果能给些学习汇编的建议那我就更加感谢你了.
现在有点忙,知道的请给我发封邮件,本人邮箱: [email protected]
再次感谢您的回复!
这里面是在ROM 还是在RAM中呢?
二楼的回答者,先谢谢你
但是 好象没有这条指令吧
谢谢你的答复,我现在才把问题找回来,非常感谢