1 Pertemuan 5 Bahasa Rakitan: I Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1
2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mendemonstrasikan penggunaan bahasa rakitan dalam instruksi mesin ( C3 ) ( No TIK : 3 )
3 Chapter 2. Assembly Language: I
4 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
5 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.
6
7 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.
8 Figure A stack of words in the memory. register Stack pointer 17 BOTTOM 0 SP Current top element element Bottom Stack 2 k
9 Figure Effect of stack operations on the stack in Figure (b) After pop into ITEM(a) After push from NEWITEM ITEM SP Stack SP NEWITEM
10 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
11 ReturnCall Figure Subroutine linkage using a link register Link PC Return 1000 location Memory Calling program Memory location Call SUB next instruction Subroutine SUB first instruction