0% found this document useful (0 votes)
21 views4 pages

07.02.2024 - Symmetric Ciphers

These are sum of the pdfs that u like, and get help solving assignment

Uploaded by

daksh.singh2021a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

07.02.2024 - Symmetric Ciphers

These are sum of the pdfs that u like, and get help solving assignment

Uploaded by

daksh.singh2021a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

TUTORIAL 4

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

MOV P1,A ;P1=55H

MOV P2,A ;P2=55H

(b) P1 address=80H; P2 address=A0H

MOV A,#55H ;A=55H

MOV 80H,A ;P1=55H

MOV 0A0H,A ;P2=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

PUSH 0E0H ;push register A onto stack

POP 0F0H ;pop top of stack into B

;now register B = register A

POP 02 ;pop top of stack into R2

;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

(a) MOV A,#55H ;load A with value 55H

MOV 40H,A ;copy A to RAM location 40H

MOV 41H.A ;copy A to RAM location 41H

(b) MOV A,#55H ;load A with value 55H


MOV R0,#40H ;load the pointer. R0=40H

MOV @R0,A ;copy A to RAM R0 points to

INC R0 ;increment pointer. Now R0=41h

MOV @R0,A ;copy A to RAM R0 points to

(c) MOV A,#55H ;A=55H

MOV R0,#40H ;load pointer.R0=40H,

MOV R2,#02 ;load counter, R2=3

AGAIN: MOV @R0,A ;copy 55 to RAM R0 points to

INC R0 ;increment R0 pointer

DJNZ R2,AGAIN ;loop until counter = zero

8. Write a program to clear 16 RAM locations starting at RAM address 60H. ( CLR A ; clears the
accumulator)
CLR A ;A=0

MOV R1,#60H ;load pointer. R1=60H


MOV R7,#16 ;load counter, R7=16
AGAIN: MOV @R1,A ;clear RAM R1 points to
INC R1 ;increment R1 pointer
DJNZ R7,AGAIN ;loop until counter=zero

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

11. Write a program to save the accumulator in R7 of bank 2.


CLR PSW.3
SETB PSW.4
MOV R7,A

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.

MOV A,37H ;load RAM 37H into ACC


JNB ACC.0,YES ;if D0 of ACC 0? If so jump
INC A ;it’s odd, make it even
YES: MOV P2,A ;send it to P2
14. A switch is connected to pin P1.7 and an LED to pin P2.0. Below is an example to write a
program to get the status of the switch and send it to the LED.

Solution: LED BIT P1.7 ; assign bit


SW BIT P2.0 ; assign bit
HERE: MOV C,SW ; get the bit from the port
MOV LED,C ; send the bit to the port
SJMP HERE ; repeat forever

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.

LED1 BIT P2.0


LED2 BIT P2.1
SW BIT P1.2
HERE: MOV C,SW
MOV LED1,C
MOV LED2,C
SJMP HERE

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

You might also like