Documente Academic
Documente Profesional
Documente Cultură
ECE473/573
Introduction
The MCS-51 instruction set is optimized for 8-bit control
applications.
It provides a variety of fast, compact address modes for accessing
the internal RAM to facilitate operations on small data structures.
ECE473/573
ECE473/573
ECE473/573
ECE473/573
DPTR, A
R4, R7
R4R2
R1A
R4, R2
ECE473/573
ECE473/573
ECE473/573
ECE473/573
ECE473/573
10
ECE473/573
11
ECE473/573
12
13
ECE473/573
14
ECE473/573
15
ECE473/573
16
ECE473/573
17
ECE473/573
18
ECE473/573
19
ECE473/573
20
Arithmetic Instructions
Ex3-11: The accumulator contains 63H, R3 contains 23H
and the PSW contains 00H: (a) what is the hexdecimal
content of the accumulator and the PSW after execution of
the following instruction?
ADD A, R3
(b) What is the content of the accumulator in decimal after
execution of this instruction?
Ex3-12: illustrate an instruction sequence to subtract the
content of R6 from R7 and leave the result in R7.
Q1: INC 7FH?
ECE473/573
21
Arithmetic Instructions
Ex3-13: Suppose the 8051 did not have an instruction to directly
increment an internal RAM location. How could this operation be
achieved?
Ex3-14: The accumulator contains 55H, the B register contains 22H,
and the PSW contains 00H. What are the contents of these registers
after execution of the following instruction?
Ex3-15: The accumulator contains 1FH. What is the largest value that
could be in register B such that the OV bit would not be set after
executing the following instruction?
Ex3-16: illustrate how to add two 4-digit binary-coded decimal (BCD).
The first is in internal memory locations 40H and 41H, and the second
is in locations 42H and 43H. The most significant digits are in locations
40H and 42H. Place the BCD result in locations 40H and 41H.
ECE473/573
22
ECE473/573
23
ECE473/573
24
25
ECE473/573
26
27
ECE473/573
28
29
ECE473/573
C
A, #62H
A, #96H
R7, A
A, #27H
A, #12H
R6, A
30
ECE473/573
31
ADC Application
Q11: Write a program to get hex data in the range of 00~FFH
from P1 and convert it to decimal. Save the digits in R7 (LSB),
R6, and R5. Analyze the program, assuming that P1 has a value
of FDH for data. (hex converts to decimal using DIV AB)
ECE473/573
32
Signed Number
D7
D6
D5
D4
D3
D2
D1
D0
If D7=1 Negative
If D7=0 Positive
:
1111 1111 -1 0000 0000 +1 =0000 0001 -1
0000 0000 0
0000 0001 1
:
ECE473/573
33
Overflow Problem
Q12: Show how the 8051 would represent 5.
Overflow Occurs
A carry from D6 to D7, CY=0
CY=1, but NO carry from D6 to D7.
Q13:
MOV A, #96
MOV R1, #70
ADD A, R1
Q14:
MOV A, #-128
MOV R4, #-2
ADD A, R4
ECE473/573
34
Overflow Problem
Q15:
MOV A, #-2
MOV R1, #-5
ADD A, R1
Q16:
MOV A, #7
MOV R4, #18
ADD A, R4
ECE473/573
35
36
37
ECE473/573
38
ECE473/573
39
Rotate Right
RR A: rotate right A
MSB
LSB
Q8:
MOV A, #36H
RR
A
RR
A
ECE473/573
40
Rotate Left
RL A: rotate left A
MSB
LSB
Q9:
MOV A, #72H
RL
A
RL
A
ECE473/573
41
MSB
LSB
CY
Q10-1:
CLR C
MOV A, #26H
RRC A
ECE473/573
42
CY
MSB
LSB
Q10-2:
CLR C
MOV A, #5AH
RLC A
ECE473/573
43
SWAP
D7~D4
D3~D0
D3~D0
D7~D4
Q11:
MOV A, #72H
SWAP A
Q12: Write a program that finds the number of 1s in a
given byte.
ECE473/573
44
ASCII
Binary
BCD (unpacked)
30
011 0000
0000 0000
31
011 0001
0000 0001
32
011 0010
0000 0010
33
011 0011
0000 0011
34
011 0100
0000 0100
35
011 0101
0000 0101
36
011 0110
0000 0110
37
011 0111
0000 0111
38
011 1000
0000 1000
39
011 1001
0000 1001
ECE473/573
45
BCD ASCII
Real Time Clock: RTC (Time and Date)
Need BCD ASCII for display
Packed BCD to ASCII
DS5000T microcontroller has a RTC. The RTC provides the time of
day (Hour:Minute:Second) and the date regardless of whether
power off or on.
ECE473/573
46
ASCII
Unpacked Packed
BCD
BCD
34
37
0000 0111
ECE473/573
47
ECE473/573
48
ECE473/573
49
Boolean Instructions
Q1: Write an instruction sequence for the AND gate.
ECE473/573
50