Presentation is loading. Please wait.

Presentation is loading. Please wait.

Figure 2.1. Binary, signed-integer representations.

Similar presentations


Presentation on theme: "Figure 2.1. Binary, signed-integer representations."— Presentation transcript:

1 Figure 2.1. Binary, signed-integer representations.
V alues represented Sign and b b b b magnitude 1' s complement 2' s complement 3 2 1 1 1 1 + 7 + 7 + 7 1 1 + 6 + 6 + 6 1 1 + 5 + 5 + 5 1 + 4 + 4 + 4 1 1 + 3 + 3 + 3 1 + 2 + 2 + 2 1 + 1 + 1 + 1 + + + 1 - - 7 - 8 1 1 - 1 - 6 - 7 1 1 - 2 - 5 - 6 1 1 1 - 3 - 4 - 5 1 1 - 4 - 3 - 4 1 1 1 - 5 - 2 - 3 1 1 1 - 6 - 1 - 2 1 1 1 1 - 7 - - 1 Figure Binary, signed-integer representations.

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

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

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

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

6 • for positive numbers for negative numbers
32 bits b b b b 31 30 1 Sign bit: b = for positive numbers 31 b = 1 for negative numbers 31 (a) A signed integer 8 bits 8 bits 8 bits 8 bits ASCII ASCII ASCII ASCII character character character character (b) Four characters Figure 2.6. Examples of encoded information in a 32-bit word.

7 • • Figure 2.7. Byte and word addressing. W ord address Byte address
1 2 3 3 2 1 4 4 5 6 7 4 7 6 5 4 k k k k k k k k k k 2 - 4 2 - 4 2 - 3 2 - 2 2 - 1 2 - 4 2 - 1 2 - 2 2 - 3 2 - 4 (a) Big-endian assignment (b) Little-endian assignment Figure Byte and word addressing.

8 Please see “portrait orientation” PowerPoint file for Chapter 2
Figure A program for C ¬ [A] + [B].

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

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

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

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

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

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

15 Move #LIST,R0 Clear R1 Clear R2 Clear R3 Move N,R4 LOOP Add 4(R0),R1 Add 8(R0),R2 A d d 12(R0),R3 Add #16,R0 Decrement R4 Branch>0 LOOP Move R1,SUM1 Move R2,SUM2 Move R3,SUM3 Figure Indexed addressing used in accessing test scores in the list in Figure 2.14.

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

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

18 Memory Addressing address or data lab el Op eration information Assem bler directiv es SUM EQU 200 ORIGIN 204 N D A T A W ORD 100 NUM1 RESER VE 400 ORIGIN 100 Statemen ts that ST AR T MO VE N,R1 generate MO VE #NUM1,R2 mac hine CLR R0 instructions LOOP ADD (R2),R0 ADD #4,R2 DEC R1 BGTZ LOOP MO VE R0,SUM Assem bler directiv es RETURN END ST AR T Figure Assembly language representation for the program in Figure 2.17.

19

20 Mo v e #LOC,R0 Initialize p oin ter register R0 to p oin t to the address of the first lo cation in memory where the c haracters are to b e stored. READ T estBit #3,INST A TUS W ait for a c haracter to b e en tered Branc h=0 READ in the k eyb oard buffer D A T AIN. Mo v eByte D A T AIN,(R0) T ransfer the c haracter from D A T AIN in to the memory (this clears SIN to 0). ECHO T estBit #3,OUTST A TUS W ait for the displa y to b ecome ready . Branc h=0 ECHO Mo v eByte (R0),D A T A OUT Mo v e the c haracter just read to the displa y buffer register (this clears SOUT to 0). Compare #CR,(R0)+ Chec k if the c haracter just read is CR (carriage return). If it is not CR, then Branc h 0 READ branc h bac k and read another c haracter. Also, incremen t the p oin ter to store the next c haracter. Figure A program that reads a line of characters and displays it.

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

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

23 SAFEPOP Compare #2000,SP Chec k to see if the stac k p oin ter con
tains Branc h > EMPTYERR OR an address v alue greater than 2000. If it do es, the stac k is empt y . Branc h to the routine EMPTYERR OR for appropriate action. Mo v e (SP)+,ITEM Otherwise, p op the top of the stac k in to memory lo cation ITEM. (a) Routine for a safe pop operation SAFEPUSH Compare #1500,SP Chec k to see if the stac k p oin ter Branc h FULLERR OR con tains an address v alue equal to or less than 1500. If it do es, the stac k is full. Branc h to the routine FULLERR OR for appropriate action. Mo v e NEWITEM, (SP) Otherwise, push the elemen t in memory lo cation NEWITEM on to the stac k. (b) Routine for a safe push operation Figure Checking for empty and full errors in pop and push operations.

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

25 Calling program Mo v e N,R1 R1 serv es as a coun ter. Mo v e #NUM1,R2 R2 p oints to the list. Call LIST ADD Call subroutine. Mo v e R0,SUM Sa v e result. . . . Subroutine LIST ADD Clear R0 Initialize sum to 0. LOOP Add (R2)+,R0 Add en try from list. Decremen t R1 Branc h > LOOP Return Return to calling program. Figure Program of Figure 2.16 written as a subroutine; parameters passed through registers.

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

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

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

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

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

31 Mo v e #LOC,R0 R0 points to data. Mo v eByte (R0)+,R1 Load first b yte in to R1. LShiftL #4,R1 Shift left b y 4 bit p ositions. Mo v eByte (R0),R2 Load second b yte in to R2. And #$F,R2 Eliminate high-order bits. Or R1,R2 Concatenate the BCD digits. Mo v eByte R2,PACKED Store the result. Figure A routine that packs two BCD digits.

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

33 Figure 2.33. A program for computing the dot product of two vectors.
Mo v e #A VEC,R1 R1 p oin ts to v ector A. Mo v e #BVEC,R2 R2 p oin ts to v ector B. Mo v e N,R3 R3 serv es as a coun ter. Clear R0 R0 accum ulates the dot pro duct. LOOP Mo v e (R1)+,R4 Compute the pro duct of Multiply (R2)+,R4 next comp onen ts. Add R4,R0 Add to previous sum. Decremen t R3 Decremen t the coun ter. Branc h > LOOP Loop again if not done. Mo v e R0,DOTPR OD Store dot pro duct in memory . Figure A program for computing the dot product of two vectors.

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

35 Figure 2.35. Linked-list data structure.
Link address Record 1 Record 2 Record k Head T ail (a) Linking structure Record 1 Record 2 Ne w record (b) Inserting a new record between Record 1 and Record 2 Figure Linked-list data structure.

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

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

38 Figure 2.38. A subroutine for deleting a record from a linked list.
DELETION Compare (RHEAD), RIDNUM Branch>0 SEARCH Mo v e 4(RHEAD), RHEAD not the head record Return SEARCH Mo v e RHEAD, RCURRENT LOOP Mo v e 4(RCURRENT), RNEXT Compare (RNEXT), RIDNUM Branch=0 DELETE Mo v e RNEXT , RCURRENT Branch LOOP DELETE Mo v e 4(RNEXT), R TEMP Mo v e R TEMP , 4(RCURRENT) Return Figure A subroutine for deleting a record from a linked list.

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

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


Download ppt "Figure 2.1. Binary, signed-integer representations."

Similar presentations


Ads by Google