Presentation is loading. Please wait.

Presentation is loading. Please wait.

Second word first word Figure 2.5. Memory words. n bits last word i th word.

Similar presentations


Presentation on theme: "Second word first word Figure 2.5. Memory words. n bits last word i th word."— Presentation transcript:

1 second word first word Figure 2.5. Memory words. n bits last word i th word

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

3 R0,C B,R0 A,R0 Move i + 8 Begin execution hereMove i ContentsAddress C B A the program Data for segment program 3-instruction Add i + 4 Figure 2.8. A program for C  + 

4 NUMn NUM2 NUM1 R0,SUM NUMn,R0 NUM3,R0 NUM2,R0 NUM1,R0 Figure 2.9. A straight-line program for adding n numbers. Add Move SUM i Move Add i 4n + i 4n4-+ i8+ i4+

5 N,R1Move NUMn NUM2 NUM1 R0,SUM R1 "Next" number to R0 Figure 2.10. Using a loop to add n numbers. LOOP Decrement Move LOOP loop Program Determine address of "Next" number and add N SUM n R0Clear Branch>0

6 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

7 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

8 Operand1020 Figure 2.13. Indexed addressing. Add 1000(R1),R2 R1 Add 20(R1),R2 Operand1020 201000 20 = offset 1000 (a) Offset is given as a constant (b) Offset is in the index register

9 Figure 2.14. A list of students' marks. Student 1 Student 2 Test 3 Test 2 Test 1 Student ID Test 3 Test 2 Student ID n N LIST Test 1LIST + 4 LIST + 8 LIST + 12 LIST + 16

10 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

11 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

12 NUM2 NUMn NUM1 R0Clear R0,SUM R1 #4,R2 (R2),R0 Figure 2.17. Memory arrangement for the program in Figure 2.12. 100 132 604 212 208 204 200 128 124 120 116 112 108 104 100 SUM N LOOP Decrement Add Move #NUM1,R2 N,R1Move Branch>0

13 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.

14

15 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 2.20. A program that reads a line of characters and displays it.


Download ppt "Second word first word Figure 2.5. Memory words. n bits last word i th word."

Similar presentations


Ads by Google