








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Name : Farwa Rashid Roll no.: l Section: EE5B
The target address for DJNZ is C:0009 each time it is run. DJNZ R1,AGAIN It will work such that it depends on the value of R1. R1 here is 5, so DJNZ will operate 5 times, each time at the target address C:0009.
org 0x000F mov A,#0AH Org points at 0F location A(ACC) stores value 0AH i.e A=0AH acall double Acall can call a function at a distance upto 2K bytes. It calls the function double here: mov P1,A sjmp here double: add A,0E0H lcall complement ret Add A,0E0H A=0AH(value at 0E0H)+0AH=14H Lcall can call a function upto a distance of 64K bytes. It calls the function complement which takes the complement of A. Ret takes back to the label call double after we get the output for complement label.
complement: cpl A mov P1,A ret end cpl A A=EBH mov P1,A P1=EBH ret returns to the label where complement was called Ret took us to lcall complement. And the ret after that took us to acall double. Acall double was already performed so we went to here label. here: mov P1,A sjmp here
Sjmp gives a short jump of 2 bytes to here. And the process repeats.
In part b, we are supposed to use acall instead of lcall to call the complement label in double label. double: add A,0E0H acall complement ret
jb acc.0,mul_2 //check 0th bit of Jb jump if bit.0= (will not jump in this case bec acc.0=0) No displacement bec acc.0= 0005 mov b,#2 B 2 0008 mul ab Mul ab ab(2H2) It gives A=4H and B=0H 0009 mov b,#3 B 3 000C div ab Div ab a/b 4/ It gives A= 1H and B=1H 000D mov p2,a P2A P2 1H 000F sjmp again Will jump to again infinite times Displacement of 000FH-0000H=000FH (16 bytes) 0011 mul_2: 0011 mov b,# 0014 mul ab 0015 mov b,# 0018 div ab 0019 mov p2,b Will not be implemented in this case end Code will end here org 0x 0000 again: 0000 mov p1,a 0002 jb acc.0,mul_ A moves in P1 i.e P1=1H=0001H 0002 jb acc.0,mul_2//check 0th bit of Accumulator Jb jump if bit.0= (will jump in this case bec acc.0=1) Displacement will be 0011-0002=0009(9 bytes) 0005 mov b,# 0008 mul ab 0009 mov b,# 000C div ab 000D mov p2,a 000F sjmp again Will not be implemented in this case 0011 mul_2: 0011 mov b,#3 B 3H
0014 mul ab Mul ab ab(1H3) A=3H B=0H 0015 mov b,#2 B2H 0018 div ab div aba/b3H/2H A=1H B=1H 0019 mov p2,b P21H end Code will end here
org 0x again: mov p1,a A moves in P1 i.e P1=9H=1001H jb acc.0,mul_2 //check 0th bit of Jb jump if bit.0= (will jump in this case bec acc.0=1) Displacement will be 0011-0002=0009(9 bytes) 0005 mov b,# 0008 mul ab 0009 mov b,# 000C div ab 000D mov p2,a 000F sjmp again Will not be implemented in this case 0011 mul_2: 0011 mov b,#3 B 3H 0014 mul ab Mul ab ab(9H3) A=1BH B=0H 0015 mov b,#2 B2H 0018 div ab div aba/b1BH/2H A=0EH B=1H 0019 mov p2,b P21H end Code will end here
Freq=500Hz T=
500 Hz =2ms So square wave has a time period of 2ms 75% duty shows P1.0=1 at 0.75x2ms= 1.5ms P1.0=0 at 0.25x2ms= 0.5 ms I generated a code of 0.5ms. For 1.5ms I called it thrice so it gives a delay of 1.5.μ 1MC= A X
fosc = 12 x
Total MC’s= T req 1 MC = 0.5 ms 0.5 μ = 1000 1000 2 x 255 = 1.96 approx 2 Delay 0f 0.5ms DELAY: MOV R0, # RELOAD_R1: MOV R1, # AGAIN: DJNZ R1, AGAIN DJNZ R0, RELOAD_R Then I implemented it for Square wave with 75% duty cycle org 0000H start: setb P1. ACALL DELAY ACALL DELAY ACALL DELAY CLR P1.
ACALL DELAY jmp endcode DELAY: MOV R0,# RELOAD_R1: MOV R1,# AGAIN: DJNZ R1,AGAIN DJNZ R0, RELOAD_R RET endcode: end
org 0000H mov R1,#
DJNZ R3, here down: mov R5,A mov A,01H CJNE R4, #00H ,NotSame mov R5,A jmp down NotSame2: CJNE R4, #01H, NotSame mov R6,A jmp down NotSame3: dec R Product: mov B,01H MUL AB DJNZ R4,Product down1: mov R6,A mov B,R MUL AB jmp ENDCODE PowerZero: Mov A,# ENDCODE: End
org 0000H mov 01H,# mov A,01H MOV DPTR ,#Integer MOVC A,@ A+DPTR MOV 0AH,A MOV A,01H MOV DPTR ,#Decimalpart MOVC A,@ A+DPTR MOV 0BH,A JMP ENDCODE Integer:DB 0,1,1,1,1,1,1,1,2,2,2,2,2,2,2, Decimalpart:DB 0,00,25,44,58,70,81,91,00,08,15,22,28,35,41,
inc R JMP AGAIN increaseR1: INC R JMP AGAIN CheckR0is5: CJNE R0, #5, ENDCODE MOV DPTR, #MESS AGAIN1: MOV A, R MOVC A, @A+DPTR JZ startsenddata check2: CJNE A, #06CH, increaseR inc R inc R JMP AGAIN increaseR11: INC R JMP AGAIN startsenddata1: MESS1:DB "My name is Farwa", jmp check startsenddata2: MESS2:DB "Farwa is a girl", jmp check
ENDCODE: END