Sie sind auf Seite 1von 4

ECP2036 Microprocessor Systems and Interfacing Tutorial 3

TUTORIAL 3

THE 8051 ASSEMBLY LANGUAGE PROGRAMMING

1. Using the MCS-51 opcode map, find out the machine codes of the following
assembly language program and their addresses in the program memory.
ORG 0000H
MOV R0, #30H
LOOP: MOV P1, @R0 ; P1 register at address 90H
INC R0
CJNE R0, #40H, LOOP
END

2. A fragment of an assembly language program is shown below:


ORG 0100H
CVRT: MOVC A, @A+PC
RET
Num: DB 01H, 23H, 45H, 67H, 89H, 0ABH, 0CDH, EFH
END
Find the final value of ‘A’ after execution of the above instructions if initially:
i. A = 00H
ii. A = 03H
iii. A = 06H

3. Find the contents of the accumulator and the PSW register of an 8051 microcontroller
after it executes each instruction below. (Assume that initially PSW contains 00H)
MOV A, #98H
ADD A, #87H
MOV B, #12H
SUBB A, B ; B register is at address F0H

4. Write a program to implement the logic operation as shown in the figure below.
Label Bit address
V
V 90H
W
Z W 91H
X
X 92H
Y
Y 93H
Z 94H

5. For an 8-bit number, bits 0 & 1 to be cleared, bits 3 & 4 are to be set and bits 5 & 7
are to be inverted. Assuming the number is in accumulator, write assembly language
instructions for 8051 to carry out the task using logical operators with appropriate
masks. If the initial value in accumulator is 0E7H, find the final value in the
accumulator at the end of execution of the above instructions.

6. Internal RAM locations 3FH and 40H contain 91H and 05H respectively. Assuming
that the contents of PSW is initially 0, find the values of the following registers for
execution of the following program:
i. Accumulator, B and PSW registers after the ‘MUL’ instruction

2014 Multimedia University page 1


ECP2036 Microprocessor Systems and Interfacing Tutorial 3

ii. Accumulator, B and PSW registers after the ‘DIV’ instruction


MOV A, 3FH
MOV B, 40H
MUL AB
DIV AB

7. For the following subroutine, find:


i. The memory locations affected with their values.
ii. Total number of bytes required for the program.
iii. Total time to execute if 12MHz clock frequency is used.
FUNC1: MOV R0, #7FH
LOOP1: MOV @R0, #0FFH
DEC R0
CJNE R0, #5FH, LOOP1
MOV R1, #30H
LOOP2: MOV @R1, #00H
INC R1
CJNE R1, #60H, LOOP2
RET

8. An 8051 assembly language program is listed below:


ORG 0000H
CLR A
PUSH 30H
MOV R0, #30H
MOV DPTR, #0FA0H
MOVC A, @A+DPTR
MOV R1, A
MOV A, #01H
MOVC A, @A+DPTR
CPL A
ADD A, R1
MOV @R0, A
END
The contents of internal RAM, ROM and registers prior to the execution of the
program are as follows:
Internal RAM Contents ROM Contents Register Contents
30H 12H 0FA0H 25H R0 67H
31H 23H 0FA1H A5H R1 78H
32H 34H 0FA2H 32H ACC 89H
33H 45H 0FA3H F1H SP 07H
34H 56H 0FA4H 64H DPTR 0000H
i. Find the total size of the program in bytes.
ii. Determine the address of each instruction in the program.
iii. What are the contents of R0, R1, ACC, SP and DPTR after the execution of this
instruction sequence?

9. The process system shown in the figure below is to be controlled by a


microcontroller, which involves performing the following process:
 The tank is filled with solution A through a solenoid valve VA.
 When the solution reaches level LA, valve VA is closed and the tank is now filled
with solution B through valve VB.
 When the solution in the tank reaches level LB, valve VB is closed.
 Both the mixer motor and the heater then start for approximately one minute.
 After that, the drainage valve VE opens to empty the tank.

2014 Multimedia University page 2


ECP2036 Microprocessor Systems and Interfacing Tutorial 3

 When the solution reaches level LE, valve VE is closed and the whole process is
repeated.
The tank has three level sensors that send signals to input lines P2.0 to P2.2. A logical
low from the sensor indicates that the level has been reached. The output lines P1.1 to
P1.3 provide signals to the solenoid valves. A logical high from the lines will open
the corresponding valve. The output lines P1.0 and P1.4 provide signals to the motor
and the heater respectively. Both the motor and the heater are activated by a logical
high. Write a program for the 8051 microcontroller to carry out the process.

Motor
VB VA
M
8051
P1.0
P1.1 LB
P1.2
P1.3
P1.4

LA

P2.0
P2.1 LE
P2.2
Heater VE

Notes: The microcontroller is connected to the sensors and actuators through some drivers and
signal conditioning circuits, which are not shown here for simplicity.

10. Two dual carriage roads meet at an intersection, as shown in Figure Q10 below. Four
traffic lights (E, S, W and N) placed at this junction are to be controlled by an 8051
microcontroller. Each traffic light is controlled via different I/O pins on the
microcontroller, as shown in Table Q10.1. The operations of the traffic lights are
summarized in Table Q10.2. The operation cycle repeats indefinitely until the
microcontroller is powered down. Assume that the traffic lights are properly
connected to the microcontroller via an interfacing circuit, write a program for the
8051 microcontroller to control these traffic lights. (Note: 12MHz crystal is used).
Table Q10.1
Port 0 Port 1
Pin 0 1 2 3 4 5 0 1 2 3 4 5
Light E-R E-Y E-G W-R W-Y W-G N-R N-Y N-G S-R S-Y S-G
*R: Red, Y: Yellow, G: Green
Table Q10.2
Duration E W N S
30s Green Red Red Red
3s Yellow Red Red Red
30s Red Green Red Red
3s Red Yellow Red Red
60s Red Red Green Red
3s Red Red Yellow Red
60s Red Red Red Green
3s Red Red Red Yellow

2014 Multimedia University page 3


ECP2036 Microprocessor Systems and Interfacing Tutorial 3

N
W E
S

Figure Q10

2014 Multimedia University page 4

Das könnte Ihnen auch gefallen