0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 0...
TRANSCRIPT
0000000011111111
00000000
1111
1111
1100110000110011
1010101001010101
1+
1-
2+3+4+5+6+7+
2-3-4-5-6-7-
8-0+0-
1+2+3+4+5+6+7+
0+7-6-5-4-3-2-1-0-
1+2+3+4+5+6+7+
0+
7-6-5-4-3-2-1-
b3 b2b1b0
Sign andmagnitude 1's complement 2's complement
B Values represented
Figure 2.1. Binary, signed-integer representations.
Figure 2.2. Addition of 1-bit numbers.
Carry-out
1
1
+
011
0
1+
0
0
0
+
1
0
1
+
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.3. Modular number systems and the 2's-complement system.
Figure 2.4. 2's-complement Add and Subtract operations.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.5. Memory words.
Please see “portrait orientation” PowerPoint file for Chapter 3
Figure 2.6. Examples of encoded information in a 32-bit word.
(b) Four characters
charactercharactercharacter character
(a) A signed integer
Sign bit: for positive numbers for negative numbers
ASCIIASCIIASCIIASCII
32 bits
8 bits 8 bits 8 bits 8 bits
b31 b30 b1 b0
b31 0=
b31 1=
• • •
2k
4- 2k
3- 2k
2- 2k
1- 2k
4-2k
4-
0 1 2 3
4 5 6 7
0 0
4
2k
1- 2k
2- 2k
3- 2k
4-
3 2 1 0
7 6 5 4
Byte addressByte address
(a) Big-endian assignment (b) Little-endian assignment
4
Wordaddress
•••
•••
Figure 2.7. Byte and word addressing.
Figure 2.8.. A program for C +
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.9. A straight-line program for adding n numbers.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.10. Using a loop to add n numbers.
Please see “portrait orientation” PowerPoint file for Chapter 2
R1
Add (R1),R0 Add (A),R0
Figure 2.11. Indirect addressing.
RegisterB B Operand
memoryMain
(a) Through a general-purpose register (b) Through a memory location
A BOperandB
Clear R0
Contents
Move
Add
DecrementAdd
LOOP
Initialization
LOOP
Address
Figure 2.12. Use of indirect addressing in the program of Figure 2.10.
(R2),R0#4,R2R1
R0,SUM
MoveMove N,R1
#NUM1,R2
Branch>0
Figure 2.13. Indexed addressing.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.14. A list of students' marks.
Please see “portrait orientation” PowerPoint file for Chapter 2
Move #LIST,R0
Add
Move
Add
12(R0),R3
LOOP
Figure 2.15. Indexed addressing used in accessing test scores in the list in Figure 2.14.
#16,R0
Clear R1
Clear R3
4(R0),R1
Clear R2
Add 8(R0),R2
N,R4
Add
Decrement R4
LOOP
Move R1,SUM1
Move R2,SUM2
Move R3,SUM3
Branch>0
R0Clear
R0,SUM
R1(R2)+,R0
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
Initialization
Move
LOOP AddDecrement
LOOP
#NUM1,R2N,R1Move
Move
Branch>0
Figure 2.17. Memory arrangement for the program in Figure 2.12.
Please see “portrait orientation” PowerPoint file for Chapter 2
Memory Addressingaddress ordatalabel Operation information
Assemblerdirectives SUM EQU 200ORIGIN 204
N DATAWORD 100NUM1 RESERVE 400
ORIGIN 100Statementsthat START MOVE N,R1
generate MOVE #NUM1,R2machine CLR R0instructions LOOP ADD (R2),R0
ADD #4,R2DEC R1BGTZ LOOPMOVE R0,SUM
Assemblerdirectives RETURNEND START
Figure 2.18. Assembly language representation for the program in Figure 2.17.
DATAIN DATAOUT
SIN SOUT
Keyboard Display
Bus
Figure 2.19 Bus connection for processor, keyboard, and display.
Processor
Move #LOC,R0 InitializepointerregisterR0topoint totheaddressofthefirstlocationinmemorywherethecharactersareto bestored.
READ TestBit #3,INSTATUS Wait for a characterto beenteredBranch=0 READ in thekeyboardbufferDATAIN.MoveByte DATAIN,(R0) Transferthecharacterfrom DATAIN into
thememory(thisclearsSIN to 0).ECHO TestBit #3,OUTSTATUS Waitforthedisplay to becomeready.
Branch=0 ECHOMoveByte (R0),DATAOUT Movethecharacterjustreadtothedisplay
bufferregister(thisclearsSOUT to 0).Compare #CR,(R0)+ Check if thecharacterjustread is CR
(carriagereturn). If it isnotCR,thenBranch0 READ branch back andreadanothercharacter.
Also,increment thepointertostorethenextcharacter.
Figure 2.20. A program that reads a line of characters and displays it.
Figure 2.21. A stack of words in the memory.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.22. Effect of stack operations on the stack in Figure 2.21.
Please see “portrait orientation” PowerPoint file for Chapter 2
SAFEPOP Compare #2000,SP Check toseeif thestack pointercontainsBranch>0 EMPTYERROR anaddressvaluegreaterthan2000. If it
does,thestack isempty. Branch totheroutineEMPTYERROR forappropriateaction.
Move (SP)+,ITEM Otherwise,popthetopofthestack intomemorylocationITEM.
SAFEPUSH Compare #1500,SP Check tosee if thestack pointerBranch 0 FULLERROR contains anaddressvalueequal
to orlessthan1500. If it does,thestack is full.Branch totheroutineFULLERROR forappropriateaction.
Move NEWITEM, (SP) Otherwise,pushtheelement inmemorylocation NEWITEMontothestack.
–
Figure 2.23. Checking for empty and full errors in pop and push operations.
(b) Routine for a safe push operation
(a) Routine for a safe pop operation
Figure 2.24. Subroutine linkage using a link register.
Please see “portrait orientation” PowerPoint file for Chapter 2
Callingprogram
Move N,R1 R1servesasacounter.Move #NUM1,R2 R2 pointstothelist.Call LISTADD Callsubroutine.Move R0,SUM Save result....
Subroutine
LISTADD Clear R0 Initializesumto0.LOOP Add (R2)+,R0 Add entryfromlist.
Decrement R1Branch>0 LOOPReturn Returntocallingprogram.
Figure 2.25. Program of Figure 2.16 written as a subroutine; parameters passed through registers.
Figure 2.26. Program of Figure 2.16 written as a subroutine; parameters passed on the stack.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.27. A subroutine stack frame example.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.28. Nested subroutines.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.29. Stack frames for Figure 2.28.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.30. Logical and arithmetic shift instructions.
Please see “portrait orientation” PowerPoint file for Chapter 2
Move #LOC,R0 R0pointstodata.MoveByte (R0)+,R1 Loadfirstbyte intoR1.
LShiftL #4,R1 Shiftleftby 4 bit positions.MoveByte (R0),R2 Loadsecondbyte intoR2.And #$F,R2 Eliminatehigh-orderbits.Or R1,R2 ConcatenatetheBCDdigits.MoveByte R2,PACKED Storetheresult.
Figure 2.31. A routine that packs two BCD digits.
Figure 2.32. Rotate instructions.
Please see “portrait orientation” PowerPoint file for Chapter 2
Move #AVEC,R1 R1 pointstovectorA.Move #BVEC,R2 R2 pointsto vectorB.Move N,R3 R3serves asacounter.Clear R0 R0accumulatesthedotproduct.
LOOP Move (R1)+,R4 ComputetheproductofMultiply (R2)+,R4 nextcomponents.Add R4,R0 Addtoprevioussum.
Decrement R3 Decrementthecounter.Branch>0 LOOP Loopagainif notdone.Move R0,DOTPROD Storedotproductinmemory.
Figure 2.33. A program for computing the dot product of two vectors.
Figure 2.34. A byte-sorting program using a straight-selection sort.
Please see “portrait orientation” PowerPoint file for Chapter 2
Record 1
(a) Linking structure
Record 2 Record k
Link address
Head Tail
0
Record 2Record 1
Ne w record
(b) Inserting a new record between Record 1 and Record 2
Figure 2.35. Linked-list data structure.
Figure 2.36. A list of student test scores organized as a linked list in memory.
Please see “portrait orientation” PowerPoint file for Chapter 2
Figure 2.37. A subroutine for inserting a new record into a linked list.
Please see “portrait orientation” PowerPoint file for Chapter 2
DELETION Compare (RHEAD), RIDNUMBranch>0 SEARCH
Move 4(RHEAD), RHEADReturnMove RHEAD, RCURRENT
Move 4(RCURRENT), RNEXTCompare (RNEXT), RIDNUMBranch=0 DELETE
Move RNEXT , RCURRENTBranchMove 4(RNEXT), RTEMP
RTEMP , 4(RCURRENT)
Return
LOOP
Move
not the head record
SEARCH
LOOP
DELETE
Figure 2.38. A subroutine for deleting a record from a linked list.
Figure 2.39. Encoding instructions into 32-bit words.
Please see “portrait orientation” PowerPoint file for Chapter 2
Table 2.1. Generic addressing modes.
Please see “portrait orientation” PowerPoint file for Chapter 2