1.
Write assembly language program using microcontroller 8051
simulator, to
a. Add two 16 bit numbers kept in registers R1, R2, R3, R4 of
Register Bank 1. Store the result in R5, R6, R7 of Register Bank 1.
b. Subtract two 16 bit numbers kept in registers R1, R2, R3, R4 of
register Bank 2. Store the result in R5 R6 R7 of register Bank 2.
c. Add five 8 bit hex numbers stored in RAM locations starting at 40
H. Put the result in R5 and R6 of Register Bank 0.
d. Multiply two 8 bit numbers stored at memory locations 40H and
41H and put the result in 42H and 43H.
e. Divide two 8 bit numbers stored in memory locations 18H and
19H. Put the result quotient at 20H and remainder at 21H.
f. Convert the hex numbers stored at R0 to equivalent decimal.
Save the decimal digits in R7, R6 and R5 where the LSB is in R7.
g. Copy a block of 10 bytes of data from RAM location starting at
35H to RAM location starting at 60H.
1a)
SETB PSW.3
CLR C
MOV R7,#00H
MOV R1,#99H
MOV R2,#88H
MOV R3,#0AAH
MOV R4,#0BBH
MOV A,R1
ADD A,R3
MOV R5,A
MOV A,R2
ADDC A,R4
JNC HERE
INC R7
HERE: MOV R6,A
1b)
SETB PSW.4
CLR C
MOV R7,#00H
MOV R1,#0AAH
MOV R2,#0BBH
MOV R3,#88H
MOV R4,#99H
MOV A,R1
SUBB A,R3
MOV R5,A
MOV A,R2
SUBB A,R4
MOV R6,A
1c)
MOV 40H,#71H
MOV 41H,#11H
MOV 42H,#65H
MOV 43H,#59H
MOV 44H,#37H
MOV R0,#40H
MOV R2,#5
CLR A
MOV R7,A
HERE: ADD A,@R0
JNC NEXT
INC R7
NEXT: INC R0
DJNZ R2,HERE
1d)
MOV 40H,#25H
MOV 41H,#65H
MOV A,40H
MOV B,41H
MUL AB
MOV 42H,A
MOV 43H,B
1e)
MOV 18H,#95
MOV 19H,#10
MOV A,18H
MOV B,19H
DIV AB
MOV 20H,A
MOV 21H,B
1f)
MOV R0,#0FDH
MOV B,#10
MOV A,R0
DIV AB
MOV R7,B
MOV B,#10
DIV AB
MOV R6,B
MOV R5,A
1g)
MOV 35H,#11H
MOV 36H,#22H
MOV 37H,#33H
MOV 38H,#44H
MOV 39H,#55H
MOV 3AH,#66H
MOV 3BH,#77H
MOV 3CH,#88H
MOV 3DH,#99H
MOV 3EH,#0AAH
MOV R0,#35H
MOV R1,#60H
MOV R3,#10H
BACK: MOV A,@R0
MOV @R1,A
INC R0
INC R1
DJNZ R3,BACK
2. Write a program using 8051 assembly language to:
a. Toggle all the bits of port P0, P1 and P2 after specified time
delay. Use delay subroutine to specify delay.
b. Create a square wave of 50 % duty cycle on bit zero of port 1.
c. Create a square wave of 66% duty cycle on bit 3 of port 1.
d. Toggle the port bit P1.3, P1.7 and P2.5 continuously without
disturbing the rest of the bits.
2a)
BACK: MOV A,#55H
MOV P0,A
MOV P1,A
MOV P2,A
LCALL DELAY
MOV A,#0AAH
MOV P0,A
MOV P1,A
MOV P2,A
LCALL DELAY
SJMP BACK
DELAY: MOV R3,#20
HERE: DJNZ R3,HERE
RET
2b &c)
BACK: SETB P1.3
LCALL DELAY
CLR P1.3
LCALL DELAY
SJMP BACK
DELAY: MOV R3,#20
HERE: DJNZ R3,HERE
RET
2d)
BACK: SETB P1.3
SETB P1.7
SETB P2.5
LCALL DELAY
CLR P1.3
CLR P1.7
CLR P2.5
LCALL DELAY
SJMP BACK
DELAY: MOV R3,#20
HERE: DJNZ R3,HERE
RET