Transcript Part Two

n bits
first word
second word
•
•
•
i th word
•
•
•
last word
Figure 2.5. Memory words.
32 bits
b1
•
•
•
b31 b30
b0
Sign bit: b31= 0 for positive numbers
b31= 1 for negative numbers
(a) A signed integer
8 bits
8 bits
8 bits
8 bits
ASCII
character
ASCII
character
ASCII
character
ASCII
character
(b) Four characters
Figure 2.6. Examples of encoded information in a 32-bit word.
Address
Begin execution here
i
i +4
i +8
Contents
Move
Add
Move
A,R0
B,R0
R0,C
3-instruction
program
segment
A
B
C
Figure 2.8. A program for C  [A] + [B].
Data for
the program
i
i + 4
i + 8
i + 4n - 4
i + 4n
SUM
NUM1
NUM2
NUM n
Move
Add
Add
Add
Move
NUM1,R0
NUM2,R0
NUM3,R0
•
•
•
NUM n ,R0
R0,SUM
•
•
•
•
•
•
Figure 2.9. A straight-line program for adding n numbers.
Move
Clear
LOOP
Program
loop
N,R1
R0
Determine address of
"Next" number and add
"Next" number to R0
Decrement
Branch>0
Move
SUM
N
NUM1
NUM2
NUM n
R1
LOOP
R0,SUM
•
•
•
n
•
•
•
Figure 2.10. Using a loop to add n numbers.
Add
(R1),R0
Add
(A),R0
Main
memory
B
R1
Operand
B
Register
(a) Through a general-purpose register
A
B
B
Operand
(b) Through a memory location
Figure 2.11. Indirect addressing.
Address
LOOP
Contents
Move
Move
Clear
Add
Add
Decrement
Branch>0
Move
N,R1
#NUM1,R2
R0
(R2),R0
#4,R2
R1
LOOP
R0,SUM
Initialization
Figure 2.12. Use of indirect addressing in the program of Figure
2.10.
Add
20(R1),R2
1000
1000
R1
20
R1
20 = offset
1020
Operand
(a) Offset is given as a constant
Add
1000(R1),R2
1000
20 = offset
1020
Operand
(b) Offset is in the index register
Figure 2.13. Indexed addressing.
n
Student ID
Test 1
Test 2
N
LIST
LIST + 4
LIST + 8
LIST + 12
LIST + 16
Test 3
Student ID
Test 1
Test 2
Test 3
•
•
•
Figure 2.14. A list of students' marks.
Student 1
Student 2
LOOP
Move
#LIST,R0
Clear
R1
Clear
R2
Clear
R3
Move
N,R4
Add
4(R0),R1
Add
8(R0),R2
A dd
12(R0),R3
Add
#16,R0
Decrement
R4
Branch>0
LOOP
Move
R1,SUM1
Move
Move
R2,SUM2
R3,SUM3
Figure 2.15. Indexed addressing used in accessing test scores in the list in Figure
2.14.
LOOP
Move
Move
Clear
Add
Decrement
Branch>0
Move
N,R1
#NUM1,R2
R0
(R2)+,R0
R1
LOOP
R0,SUM
Initialization
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
LOOP
100
104
Move
Move
N,R1
#NUM1,R2
108
112
116
Clear
Add
Add
R0
(R2),R0
#4,R2
120
124
128
132
Decrement
Branch>0
Move
R1
LOOP
R0,SUM
SUM
N
200
204
NUM1
NUM2
208
212
NUM n
604
100
Figure 2.17. Memory arrangement for the program in Figure 2.12.
Memory
address
label
Assembler directives
SUM
N
NUM1
Statemen
ts that
generate
machine
instructions
Assemblerdirectives
START
LOOP
Operation
EQU
ORIGIN
DATAWORD
RESERVE
ORIGIN
MOVE
MOVE
CLR
ADD
ADD
DEC
BGTZ
MOVE
RETURN
END
Addressing
or data
information
200
204
100
400
100
N,R1
#NUM1,R2
R0
(R2),R0
#4,R2
R1
LOOP
R0,SUM
START
Figure 2.18. Assembly language representation for the program in Figure 2.17.
Figure 2.19 Bus connection for processor
, keyboard, and display
.
Move
#LOC,R0
READ
TestBit
Branch=0
MoveByte
#3,INSTATUS
READ
DATAIN,(R0)
ECHO
TestBit
Branch=0
MoveByte
#3,OUTSTATUS
ECHO
(R0),DATAOUT
Compare
#CR,(R0)+
Branch0
READ
Initialize pointer registerR0 to point to the
addressof the first locationin memory
wherethe charactersare to be stored.
Wait for a characterto be entered
in the keyboard buffer DATAIN.
Transferthe characterfrom DATAIN into
the memory(this clears SIN to 0).
Wait for the display to becomeready.
Move thecharacterjust read to the display
buffer register(this clearsSOUT to 0).
Check if the characterjust read is CR
(carriagereturn). If it is not CR, then
branch back and read anothercharacter.
Also, increment the pointer to store the
next character.
Figure 2.20. A program that reads a line of characters and displays it.