# 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 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1+ 1- 2+ 3+ 4+ 5+ 6+ 7+

## Presentation on theme: "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 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1+ 1- 2+ 3+ 4+ 5+ 6+ 7+"— Presentation transcript:

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 1 0 1 0 1 0 0 1 0 1 0 1 0 1 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- b 3 b 2 b 1 b 0 Sign and magnitude 1's complement2's complement BValues 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 character (a) A signed integer Sign bit: for positive numbers for negative numbers ASCII 32 bits 8 bits b 31 b 30 b 1 b 0 b 31 0= b 1=

2 k 4-2 k 3-2 k 2-2 k 1-2 k 4-2 k 4- 0123 4567 0 0 4 2 k 1-2 k 2-2 k 3-2 k 4- 3210 7654 Byte address (a) Big-endian assignment(b) Little-endian assignment 4 Word address 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),R0Add (A),R0 Figure 2.11. Indirect addressing. Register BB Operand memory Main (a) Through a general-purpose register(b) Through a memory location ABOperandB

ClearR0 Contents Move Add Decrement Add LOOP Initialization LOOP Address Figure 2.12. Use of indirect addressing in the program of Figure 2.10. (R2),R0 #4,R2 R1 R0,SUM Move 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 ClearR1 ClearR3 4(R0),R1 ClearR2 Add8(R0),R2 N,R4 Add DecrementR4 LOOP MoveR1,SUM1 Move R2,SUM2 MoveR3,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 LOOPAdd Decrement LOOP #NUM1,R2 N,R1Move Branch>0

Figure 2.17. Memory arrangement for the program in Figure 2.12. Please see “portrait orientation” PowerPoint file for Chapter 2

MemoryAddressing addressordata labelOperationinformation AssemblerdirectivesSUMEQU200 ORIGIN204 NDATAWORD100 NUM1RESERVE400 ORIGIN100 StatementsthatSTARTMOVEN,R1 generateMOVE#NUM1,R2 machineCLRR0 instructionsLOOPADD(R2),R0 ADD#4,R2 DECR1 BGTZLOOP MOVER0,SUM AssemblerdirectivesRETURN ENDSTART Figure 2.18. Assembly language representation for the program in Figure 2.17.

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

SAFEPOPCompare#2000,SPChecktoseeifthestackpointercontains Branch>0EMPTYERRORanaddressvaluegreaterthan2000.Ifit does,thestackisempty.Branchtothe routineEMPTYERRORforappropriate action. Move(SP)+,ITEMOtherwise,popthetopofthestackinto memorylocationITEM. SAFEPUSHCompare#1500,SPChecktoseeifthestackpointer Branch0FULLERRORcontainsanaddressvalueequal toorlessthan1500.Ifitdoes,the stackisfull.Branchtotheroutine FULLERRORforappropriateaction. MoveNEWITEM,(SP)Otherwise,pushtheelementinmemory locationNEWITEMontothestack.  – 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

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,R0R0pointstodata. MoveByte(R0)+,R1LoadfirstbyteintoR1. LShiftL#4,R1Shiftleftby4bitpositions. MoveByte(R0),R2LoadsecondbyteintoR2. And#\$F,R2Eliminatehigh-orderbits. OrR1,R2ConcatenatetheBCDdigits. MoveByteR2,PACKEDStoretheresult. 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,R1R1pointstovectorA. Move#BVEC,R2R2pointstovectorB. MoveN,R3R3servesasacounter. ClearR0 accumulatesthedotproduct. LOOPMove(R1)+,R4Computetheproductof Multiply(R2)+,R4nextcomponents. AddR4,R0Addtoprevioussum. DecrementR3Decrementthecounter. Branch >0 LOOPLoopagainifnotdone. MoveR0,DOTPRODStoredotproductinmemory. 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 2Recordk Link address HeadTail 0 Record 2 Record 1 New 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

DELETIONCompare (RHEAD), RIDNUM Branch>0SEARCH Move4(RHEAD), RHEAD Return MoveRHEAD, RCURRENT Move4(RCURRENT), RNEXT Compare(RNEXT), RIDNUM Branch=0DELETE MoveRNEXT, RCURRENT Branch Move4(RNEXT), RTEMP R, 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

Similar presentations