07.02.2024 - Symmetric Ciphers
07.02.2024 - Symmetric Ciphers
1. Write an instruction to copy data from R4 register to accumulator using direct addressing.
MOV E0,R4
2. Write an instruction to copy data from location 56H to accumulator.
MOV A,56H
3. Copy data from register B to memory location 10H using direct addressing.
MOV 0FO,10H
4. Write code to send 55H to ports P1 and P2, using their names their addresses.
(a) MOV A,#55H ;A=55H
5. Show the code to push R5 and A onto the stack and then pop them back them into R2 and B,
where B = A and R2 = R5 . (Only direct addressing mode is allowed for pushing or popping
the stack : PUSH A is invalid)
PUSH 05 ;push R5 onto stack
;now R2=R6
TUTORIAL 5
6. Move contents of RAM whose ;address is held by R0 into A. (a register is used as a pointer to
the data. Only register R0 and R1 are used for this purpose. R2 – R7 cannot be used to hold
the address of an operand located in RAM.
MOV A,@R0 ;move contents of RAM whose address is held by R0 into A
7. Write a program to copy the value 55H into RAM memory locations 40H to 41H using
a. direct addressing mode
b. register indirect addressing mode without a loop, and
c. with a loop
8. Write a program to clear 16 RAM locations starting at RAM address 60H. ( CLR A ; clears the
accumulator)
CLR A ;A=0
9. Indexed addressing mode is widely used in accessing data elements of look-up table entries
located in the program ROM. The instruction used for this purpose is MOVC A,@A+DPTR
Use instruction MOVC, “C” means code. The contents of A are added to the 16-bit register
DPTR to form the 16-bit address of the needed data.
Below is an example to write a program to get the x value from P1 and send x2 to
P2,continuously
Solution: ORG 0
MOV DPTR,#300H ;LOAD TABLE ADDRESS
MOV A,#0FFH ;A=FF
MOV P1,A ;CONFIGURE P1 INPUT PORT
BACK:MOV A,P1 ;GET X
MOV A,@A+DPTR ;GET X SQAURE FROM TABLE
MOV P2,A ;ISSUE IT TO P2
SJMP BACK ;KEEP DOING IT
ORG 300H
XSQR_TABLE:
DB 0,1,4,9,16,25,36,49,64,81
END
Write a program to get the x value from P2 and send x3 to P0, continuously
ORG 0
MOV DPTR,#300H ;LOAD TABLE ADDRESS
MOV A,#0FFH ;A=FF
MOV P2,A ;CONFIGURE P1 INPUT PORT
BACK:MOV A,P2 ;GET X
MOV A,@A+DPTR ;GET X SQAURE FROM TABLE
MOV P0,A ;ISSUE IT TO P2
SJMP BACK ;KEEP DOING IT
ORG 300H
XCUBE_TABLE:
DB 0,1,8,27,64,125,216,343,343,512,729,1000
END
10. In many applications we use RAM locations 30 – 7FH as scratch pad. We use R0 – R7 of bank
0. Leave addresses 8 – 1FH for stack usage. If we need more registers, we simply use RAM
locations 30 – 7FH.
Write a program to toggle P1 a total of 200 times. Use RAM location 32H to hold your
counter value instead of registers R0 –R7.
MOV P1,#55H ;P1=55H
MOV 32H,#C8 ;load counter value
;into RAM loc 32H
LOP1: CPL P1 ;toggle P1
ACALL DELAY
DJNZ 32H,LOP1 ;repeat 200 times
TUTORIAL 6
12. While there are instructions such as JNC and JC to check the carry flag bit (CY), there are no
such instructions for the overflow flag bit (OV). How would you write code to check OV?
JB PSW.2,TARGET ;jump if OV=1
13. Write a program to see if the RAM location 37H contains an even value. If so, send it to P2. If
not, make it even and then send it to P2.
Now, switch is connected to pin P1.2 and 2 LED’s are to pin P2.0 & P2.1. Write a program to
get the status of the switch and send it to the LED’s.
15. A switch is connected to pin P1.7. An example program is written below to check the status
of the switch and make the following decision.
(a) If SW = 0, send “0” to P2
(b) If SW = 1, send “1“ to P2
Solution:
SW EQU P1.7
MYDATA EQU P2
HERE: MOV C,SW
JC OVER
MOV MYDATA,#’0’
SJMP HERE
OVER: MOV MYDATA,#’1’
SJMP HERE
END
A switch is connected to pin P1.2. Write a program to check the status of the switch and
make the following decision.
(a) If SW = 0, send “A” to P3
(b) If SW = 1, send “B“ to P3
SW EQU P1.2
MYDATA EQU P3
HERE: MOV C,SW
JC OVER
MOV MYDATA,#’0’
SJMP HERE
OVER: MOV MYDATA,#’1’
SJMP HERE
END