Professional Documents
Culture Documents
QUESTION 22
The program in listing 6-1 clears the content in
internal data memory location 25H to32H. Modify
the program to populate the content in location 25H
to 32H as shown in figure 6-1. Your solution should
demonstrate efficiency in programming.
M1:
HG:
MOV R0,#25H
CLR A
MOV @R0,A
INC R0
CJNE R0,#33H,M1
SJMP HG
Listing 6-1
32H
31H
30H
2FH
2EH
2DH
2CH
2BH
2AH
29H
28H
27H
26H
25H
0DH
0CH
0BH
0AH
09H
08H
07H
06H
05H
04H
03H
02H
01H
00H
19H
18H
2DH
20H
02H
01H
00H
Figure
12H
0DH
25H
6-1
QUESTION 23
Find out the results of the operation shown in the table below.
Instruction
Result
MOV A, #0F5H
ORL A,#0FH
ANL A,#0FH
SWAP A
QUESTION 24
Determine the contents of the destination operands and flags after executing the following
instructions.
Instruction
MOV A,#0E5H
SUBB A,#16H
SUBB A,#2BH
23-03-2008
OV
0
INC
INC
INC
INC
48H
47H
46H
45H
13H
3FH
F5H
51H
02H
12H
01H
62H
00H
45H
Figure 2-1: Internal Data
Memory
@R0
R0
@R0
R0
QUESTION 26
Find out the results of the operation shown in the table below.
Instruction
Result
0000
ORG 0000H
0000 020050
LJMP MAIN
0050
ORG 0050H
0050
MAIN:
0050 7581A0 MOV SP,#0AH
0053 900050
MOV DPTR,#0050H
0056 7410
MOV A,#10H
0058 93
MOVC A,@A+DPTR
0059 23
RL A
005A 12005F LCALL WAIT
005D 80F1
SJMP MAIN
005F 7EF0
WAIT: MOV R6,#0F0H
0061 7F10
D1:
MOV R7,#010H
0063 DFFE
D2:
DJNZ R7,D2
0065 DEFA
DJNZ R6,D1
0067 22
RET
END
23-03-2008
48H
47H
46H
45H
13H
3FH
F5H
51H
SETB 1FH
23H
12H
22H
62H
21H
5AH
Internal Data
Memory
7FH
7EH
MAIN: JB 1EH,M1
MOV 20H,#28H
M1:
SETB 05H
23H
22H
21H
20H
18H
23H
47H
22H
12H
21H
62H
20H
8AH
Internal Data Memory
23-03-2008
10H
08H
00H
1FH
17H
0FH
07H
1EH
16H
0EH
06H
1DH
15H
0DH
05H
1CH
14H
0CH
04H
1BH
13H
0BH
03H
1AH
12H
0AH
02H
Bank 3
Bank 2
Bank 1
Bank 0
19H
11H
09H
01H
18H
10H
08H
00H
CSEG AT 00H
LJMP MAIN
CSEG AT 0100H
MAIN: MOV DPTR,#0100H
MOV R1,#0H
MOV R0,#20H
M1:
MOV A,R1
MOVC A,@A+DPTR
MOV @R0,A
INC R0
INC R1
CJNE A,#E9H,M1
HANG: SJMP HANG
020100
900100
7900
7820
E9
93
F6
08
09
B4E9F8
80FE
28H
27H
26H
25H
24H
23H
22H
21H
20H
30H
7EH
F6H
13H
20H
1EH
1FH
05H
43H
02H
01H
00H
12H
62H
45H
QUESTION 31
The contents in the program and data
memory are shown below. For the given
program, update the changes in the
memory after execution.
G1:
HG:
0033H
0032H
0031H
0030H
1EH
1FH
05H
43H
48H
47H
46H
45H
13H
3FH
F5H
51H
0002H
0001H
0000H
12H
62H
45H
02H
01H
00H
12H
62H
45H
Internal Program
Memory
23-03-2008
MOV DPTR,#0030H
MOV R0,#45H
CLR A
PUSH A
MOVC A,@A+DPTR
MOV @R0,A
INC R0
POP A
INC A
CJNE A,#4H,G1
SJMP HG
Results
QUESTION 33
The figure 4-1 shows the content in some location
of the 8051 Internal Data Memory.
Show the changes in the contents after executing
the program shown in listing 4-1.
MAIN: MOV R0,#20H
MOV R7,#0AH
M1:
MOV A,@R0
XRL A,#0FFH
MOV @R0,A
INC R0
DJNZ R7,M1
HANG:SJMP HANG
Listing 4-1
2DH
2CH
2BH
2AH
29H
28H
27H
26H
25H
24H
23H
22H
21H
20H
13H
3FH
F5H
51H
F6H
44H
12H
62H
5AH
4FH
13H
33H
6FH
12H
Figure 4-1
QUESTION 34
a) Determine the addressing modes of the destination operand in the following
instructions:
(i)
(ii)
(iii)
(iv)
23-03-2008
MOV
MOV
MOV
MOV
Instruction
77H,A
21H,#45H
@R1,45H
R7,#7EH
Addressing Mode
b)
Determine the contents of the destination operands and flags after executing
the following instructions.
Instruction
MOV A,#0A5H
SUBB A,#0A6H
ADDC A,#02H
OV
0
QUESTION 35
Write an 8051 assembly language program to fulfill the following requirements:
Compare the contents in internal memory location (D:50H) and (D:51H), and move the
larger number to internal data location (D:61H) and the smaller number to (D:60H).
QUESTION 36
Write an 8051 assembly language program to add all the contents in internal data
memory from (D:50H) to (D:60H) and store the results in internal data memory (D:70H).
QUESTION 37
Write an 8051 assembly language program to divide the number in internal data memory
at (D:40H) by the content in (D:41H) and store the Quotient of the result in (D:42H) and
remainder in (D:43H).
23-03-2008
CLR RS0
CLR RS1
MOV R0,#30H
SETB RS0
MOV R0,#13H
SETB RS1
CLR RS0
MOV R1,00H
PSW
CY
0
AC
0
F0
0
RS1
0
RS0
0
OV
0
13H
12H
11H
10H
30H
7EH
F6H
13H
09H
08H
05H
43H
02H
01H
00H
12H
62H
45H
23-03-2008
P
0
M1:
HG:
MOV R0,#25H
CLR A
MOV @R0,A
INC R0
INC A
CJNE R0,#33H,M1
SJMP HG
SOLUTION 23
Instruction
Result
MOV A, #0F5H
ORL A,#0FH
ANL A,#0FH
SWAP A
(A) = F5H
(A) = FFH
(A) = 0FH
(A) = F0H
SOLUTION 24
Instruction
MOV A,#0E5H
SUBB A,#16H
SUBB A,#2BH
OV
0
0
0
SOLUTION 25
Result
23-03-2008
(D:12H) = 78H
(A) = 0
(R1) = 12H
(A) = 78H
(D:12H) = 78H
(R1) = 13H
(D:13H) = 78H
48H
47H
46H
45H
13H
3FH
F5H F6H
51H 52H
02H
01H
00H
12H
62H
45H 47H
005CH
005BH
005AH
0059H
0058H
0057H
0056H
0055H
0054H
0053H
0052H
0051H
0050H
00H
12H
0BH
23H
93H
10H
74H
50H
00H
90H
A0H
81H
75H
0002H
0001H
0000H
50H
00H
02H
Code Memory
Explanation:
23H
22H
21H
20H
47H
12H
62H
8AH AAH
23-03-2008
28H
27H
26H
25H
24H
23H
22H
21H
20H
30H
7EH E9H
F6H 20H
13H 78H
20H 00H
1EH 79H
1FH 00H
05H 01H
43H 90H
02H
01H
00H
12H
62H 08H
45H 27H
SOLUTION 31
There is no change in the program memory. Internal data memory location D:00H is R0.
1EH
1FH
05H
43H
48H
47H
46H
45H
13H
3FH
F5H
51H
02H
01H
00H
12H
62H
45H 49H
23-03-2008
Results
(A) = 45H
(C) = 1
(A) = A2H
(B) = 0AH
(A) = 10H (B) = 02H
(A) = 0H
(A) = FFH
(D:40H) = 10H
(R0) = 40H
(A) =0FH
(D:40H) = 0FH
10
2DH
2CH
2BH
2AH
29H
28H
27H
26H
25H
24H
23H
22H
21H
20H
13H
3FH
F5H
51H
F6H
44H
12H
62H
5AH
4FH
13H
33H
6FH
12H
09H
BBH
EDH
9DH
A5H
B0H
ECH
CCH
90H
EDH
SOLUTION 34
(i)
(ii)
(iii)
(iv)
Instruction
MOV A,#0A5H
SUBB A,#0A6H
ADDC A,#02H
MOV
MOV
MOV
MOV
Instruction
77H,A
21H,#45H
@R1,45H
R7,#7EH
Addressing Mode
Direct
Direct
Register Indirect
Register
OV
0
0
0
SOLUTION 35
Notes: The SUBB (subtraction) instruction can be used to determine the smaller or larger
number between two numbers by observing the carry (or borrow) flag. If a smaller
number is subtracted by a larger number, the carry (or borrow) flag will be set. The JC
(Jump if Carry is Set) instruction can then be used to decide the course of action after
determining which number is smaller or larger.
23-03-2008
11
ORG 0000H
LJMP MAIN
ORG 0100H
MAIN: CLR C
MOV A,50H
SUBB A,51H
;
;
;
;
JC ABC
MOV 60H,51H
MOV 61H,50H
SJMP HANG
SOLUTION 36
ORG 0000H
LJMP MAIN
ORG 0200H
MAIN: MOV R1,#50H
CLR C
CLR A
M1:
ADD A,@R1
INC R1
CJNE R1,#61H,M1
MOV 70H,A
HANG: SJMP HANG
SOLUTION 37
ORG 0000H
LJMP MAIN
ORG 0090H
MAIN: MOV A,40H
MOV B,41H
DIV AB
MOV 42H,A
MOV 43H,B
HANG: SJMP HANG
23-03-2008
12
13H
12H
11H
10H
30H
7EH
F6H
13H 30H
09H
08H
05H
43H 13H
02H
01H
00H
12H
62H
45H 30H
23-03-2008
13