Beruflich Dokumente
Kultur Dokumente
Mc-2
Write a program to (a) Clear ACC, then (b) add 3 to ACC 10 times.
Write a program to (a) Clear ACC, then (b) add 3 to ACC 10 times.
AG:
Since R2 holds the count and R2 is an 8 bit register, it can hold a maximum of FFH, therefore the loop Can be repeated max of 256 times.
Write a program to (a) load ACC with 55H, and (b) Complement the ACC 700 times.
Write a program to (a) load ACC with 55H, and (b) Complement the ACC 700 times.
Since 700 is larger then 255, two registers are reqd. to Hold the count. MOV A, #55H ;A=55H MOV R3,#10 ;R3=10, outer loop MOV R2, #70 ;R2=70, inner loop CPL A ;complement A DJNZ R2, AG ;repeat it 70 times DJNZ R3, NE
NE: AG:
NE:
MOV A, R5 ;copy R5 to A JNZ NE ;jump if A is not zero MOV R5, #55H -----------------------
Find sum of 79H, F5H, and E2H. Store sum in R0 (low byte) and R5 (high byte)
Find sum of 79H, F5H, and E2H. Store sum in R0 (low byte) and R5 (high byte)
N_1:
N_2:
OV:
MOV A, #0 MOV R5,A ADD A,#79H JNC N_1 INC R5 ADD A, #0F5H INC N_2 INC R5 ADD A,#0E2H JNC OV INC R5 MOV R0,A
;clear A ;clear R5 ;A=0+79H=79H ;if no carry add next ;if CY=1, increment R5 ;A=79+F5=6E , CY=1 ;jump if CY=0 ;if CY=1, increment R5 ;A=6E+E2=50, CY=1 ;jump if CY=0 ;if CY=1, increment R5 ;R0=50H, and R5=02H
ALL CONDITIONAL JUMPS ARE SHORT JUMPS (TWO BYTE) ADDRESS OF TARGET MUST BE WITHIN
-128 TO +127
00 TO FFH
ADDRESS RANGE
0000 TO FFFFH
Instruction
JZ JNZ DJNZ CJNE A,byte CJNE reg,# data JC JNC JB JNB JBC
Action
Jump if A=0 Jump if A0 Decrement and jump if A0 Jump if A byte Jump if byte #data Jump if CY=1 Jump if CY=0 Jump if bit = 1 Jump if bit = 0 Jump if bit = 1 and clear bit
; MAIN program calling subroutines ORG 0 Main: LCALL SUBR_1 LCALL SUBR_2 LCALL SUBR_3 HERE: ; ; SUBR_1: ; ; SUBR_2: SJMP end of MAIN HERE
.... .... end of subroutine 1 .... .... RET end of subroutine 2 .... .... RET end of subroutine 3 END ;end of the asm file
; SUB_3:
CALL
INSTRUCTION
LCALL
Long Call
ACALL
Absolute CALL
LCALL
ACALL
3 BYTE
2 BYTE
16 bit address
11 bit address
ORG 0 BACK: MOV A,#55H ;load A with 55H MOV P1,A ;send 55H to port 1 MOV R4,#99H MOV R5,#67H LCALL DELAY ;time delay MOV A,#0AAH ;Load A with AA MOV P1,A ;send AAH to port 1 LCALL DELAY SJMP BACK ;keep doing this ;________this is the delay subroutine ORG 300H DELAY: PUSH 4 ;PUSH R4 PUSH 5 ;PUSH R5 MOV R4,#0FFH ;R4=FFH NEXT: MOV R5,#0FFH ;R5=255 AGAIN: DJNZ R5,AGAIN DJNZ R4,NEXT POP 5 ;POP INTO R5 POP 4 ;POP INTO R4 RET ;return to caller END ;end of asm file
After PUSH 4
After PUSH 5
0B 0A 09 00
0B 0A R4 99 00 0B
0B 0A
67
R5
99 00 0B
R4
PCH 09
PCL 08
PCH 09
PCL 08
PCH
08
0B
PCL