📄 sum_of_negative_and_positive_integers.asm
字号:
ORG 10000H
BLOCK EQU 40H
LEN EQU 20H
PSUM EQU 11H
MSUM EQU 13H
SJMP INI;jamp to initialize data block
;plus positive and negative respectively
START: MOV R7,#LEN;R7 is the number of loops
MOV R0,#BLOCK;
CLR PSUM
CLR MSUM
LOOP: MOV A,@R0;move one of data block to A
INC R0;make R0 point to the next data address of data block
CLR C
JB ACC.7,MADD;if A is negative
ADD A,PSUM;if A is positive, plus PSUM to A
MOV PSUM,A;move A to PSUM
MOV A,PSUM-1;move the higher bit of PSUM to A
ADDC A,#0;care of carry
MOV PSUM-1,A
SJMP NEXT;
MADD: ADD A,MSUM;do as same as before
MOV MSUM,A
MOV A,#0FFH;adjust the value
ADDC A,MSUM-1
MOV MSUM-1,A
NEXT: DJNZ R7,LOOP;not at the end of data block,go into next loop
SJMP FINISH
INI: MOV R0,#BLOCK
MOV R7,#LEN
MOV R1,#7H;adjust value
LOOP1: MOV A,R1
MOVC A,@A+PC;get value
MOV @R0,A;1 bit save value to data block
INC R0;1 bit; make R0 point to the next data address of data block
INC R1;1 bit; change the adjusting value
NEXT1: DJNZ R7,LOOP1;2 bits; not at the end of the data block,continue
SJMP START;2 bit; having initialized data block,go to deal with them
DATATAB: DB 00,01,02,03,04,05,06,07
DB 78h,79h,7ah,7bh,7ch,7dh,7eh,7fh
DB 80h,81h,82h,83h, 84h, 85h,86h,87h
DB 0f8h,0f9h,0fah,0fbh,0fch,0fdh,0feh,0ffh
FINISH: SJMP $
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -