Presentation is loading. Please wait.

Presentation is loading. Please wait.

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+

Similar presentations


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:

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.

2 Figure 2.2. Addition of 1-bit numbers. Carry-out

3 Please see “portrait orientation” PowerPoint file for Chapter 2 Figure 2.3. Modular number systems and the 2's-complement system.

4 Figure 's-complement Add and Subtract operations. Please see “portrait orientation” PowerPoint file for Chapter 2

5 Figure 2.5. Memory words. Please see “portrait orientation” PowerPoint file for Chapter 3

6 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=

7 2 k 4-2 k 3-2 k 2-2 k 1-2 k 4-2 k k 1-2 k 2-2 k 3-2 k Byte address (a) Big-endian assignment(b) Little-endian assignment 4 Word address Figure 2.7. Byte and word addressing.

8 Figure A program for C  +  Please see “portrait orientation” PowerPoint file for Chapter 2

9 Figure 2.9. A straight-line program for adding n numbers. Please see “portrait orientation” PowerPoint file for Chapter 2

10 Figure Using a loop to add n numbers. Please see “portrait orientation” PowerPoint file for Chapter 2

11 R1 Add (R1),R0Add (A),R0 Figure Indirect addressing. Register BB Operand memory Main (a) Through a general-purpose register(b) Through a memory location ABOperandB

12 ClearR0 Contents Move Add Decrement Add LOOP Initialization LOOP Address Figure Use of indirect addressing in the program of Figure (R2),R0 #4,R2 R1 R0,SUM Move N,R1 #NUM1,R2 Branch>0

13 Figure Indexed addressing. Please see “portrait orientation” PowerPoint file for Chapter 2

14 Figure A list of students' marks. Please see “portrait orientation” PowerPoint file for Chapter 2

15 Move #LIST,R0 Add Move Add 12(R0),R3 LOOP Figure Indexed addressing used in accessing test scores in the list in Figure #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

16 R0Clear R0,SUM R1 (R2)+,R0 Figure The Autoincrement addressing mode used in the program of Figure Initialization Move LOOPAdd Decrement LOOP #NUM1,R2 N,R1Move Branch>0

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

18 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 Assembly language representation for the program in Figure 2.17.

19

20 Move#LOC,R0InitializepointerregisterR0topointtothe addressofthefirstlocationinmemory wherethecharactersaretobestored. READTestBit#3,INSTATUSWaitforacharactertobeentered Branch=0READinthekeyboardbufferDATAIN. MoveByteDATAIN,(R0)TransferthecharacterfromDATAINinto thememory(thisclearsSINto0). ECHOTestBit#3,OUTSTATUSWaitforthedisplaytobecomeready. Branch=0ECHO MoveByte(R0),DATAOUTMovethecharacterjustreadtothedisplay bufferregister(thisclearsSOUTto0). Compare#CR,(R0)+CheckifthecharacterjustreadisCR (carriagereturn).IfitisnotCR,then Branch 00 READbranchbackandreadanothercharacter. Also,incrementthepointertostorethe nextcharacter. Figure A program that reads a line of characters and displays it.

21 Figure A stack of words in the memory. Please see “portrait orientation” PowerPoint file for Chapter 2

22 Figure Effect of stack operations on the stack in Figure Please see “portrait orientation” PowerPoint file for Chapter 2

23 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 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

24 Figure Subroutine linkage using a link register. Please see “portrait orientation” PowerPoint file for Chapter 2

25 Callingprogram MoveN,R1R1servesasacounter. Move#NUM1,R2R2pointstothelist. CallLISTADDCallsubroutine. MoveR0,SUMSaveresult.... Subroutine LISTADDClearR0Initializesumto0. LOOPAdd(R2)+,R0Addentryfromlist. DecrementR1 Branch >0 LOOP Return tocallingprogram. Figure Program of Figure 2.16 written as a subroutine; parameters passed through registers.

26 Figure Program of Figure 2.16 written as a subroutine; parameters passed on the stack. Please see “portrait orientation” PowerPoint file for Chapter 2

27 Figure A subroutine stack frame example. Please see “portrait orientation” PowerPoint file for Chapter 2

28 Figure Nested subroutines. Please see “portrait orientation” PowerPoint file for Chapter 2

29 Figure Stack frames for Figure Please see “portrait orientation” PowerPoint file for Chapter 2

30 Figure Logical and arithmetic shift instructions. Please see “portrait orientation” PowerPoint file for Chapter 2

31 Move#LOC,R0R0pointstodata. MoveByte(R0)+,R1LoadfirstbyteintoR1. LShiftL#4,R1Shiftleftby4bitpositions. MoveByte(R0),R2LoadsecondbyteintoR2. And#$F,R2Eliminatehigh-orderbits. OrR1,R2ConcatenatetheBCDdigits. MoveByteR2,PACKEDStoretheresult. Figure A routine that packs two BCD digits.

32 Figure Rotate instructions. Please see “portrait orientation” PowerPoint file for Chapter 2

33 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 A program for computing the dot product of two vectors.

34 Figure A byte-sorting program using a straight-selection sort. Please see “portrait orientation” PowerPoint file for Chapter 2

35 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 Linked-list data structure.

36 Figure A list of student test scores organized as a linked list in memory. Please see “portrait orientation” PowerPoint file for Chapter 2

37 Figure A subroutine for inserting a new record into a linked list. Please see “portrait orientation” PowerPoint file for Chapter 2

38 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 A subroutine for deleting a record from a linked list.

39 Figure Encoding instructions into 32-bit words. Please see “portrait orientation” PowerPoint file for Chapter 2

40 Table 2.1. Generic addressing modes. Please see “portrait orientation” PowerPoint file for Chapter 2


Download ppt "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+"

Similar presentations


Ads by Google