second word first word Figure 2.5. Memory words. n bits last word i th word
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=
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 +
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+
N,R1Move NUMn NUM2 NUM1 R0,SUM R1 "Next" number to R0 Figure 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
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
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
Operand1020 Figure Indexed addressing. Add 1000(R1),R2 R1 Add 20(R1),R2 Operand = offset 1000 (a) Offset is given as a constant (b) Offset is in the index register
Figure 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
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
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
NUM2 NUMn NUM1 R0Clear R0,SUM R1 #4,R2 (R2),R0 Figure Memory arrangement for the program in Figure SUM N LOOP Decrement Add Move #NUM1,R2 N,R1Move Branch>0
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.
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 00 READbranchbackandreadanothercharacter. Also,incrementthepointertostorethe nextcharacter. Figure A program that reads a line of characters and displays it.