Matakuliah Tahun Versi : T0324 / Arsitektur dan Organisasi Komputer : 2005 :1 Pertemuan 5 Bahasa Rakitan: I 1 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : • Mendemonstrasikan penggunaan bahasa rakitan dalam instruksi mesin ( C3 ) ( No TIK : 3 ) 2 Chapter 2. Assembly Language: I 3 LOOP 100 104 Move Move N,R1 #NUM1,R2 108 112 116 Clear Add Add R0 (R2),R0 #4,R2 120 124 128 132 Decrement Branch>0 Move R1 LOOP R0,SUM SUM N 200 204 NUM1 NUM2 208 212 NUM n 604 100 Figure 2.17. Memory arrangement for the program in Figure 2.12. 4 Memory address label Assembler directives SUM N NUM1 Statemen ts that generate machine instructions Assemblerdirectives START LOOP Operation EQU ORIGIN DATAWORD RESERVE ORIGIN MOVE MOVE CLR ADD ADD DEC BGTZ MOVE RETURN END Addressing or data information 200 204 100 400 100 N,R1 #NUM1,R2 R0 (R2),R0 #4,R2 R1 LOOP R0,SUM START Figure 2.18. Assembly language representation for the program in Figure 2.17. 5 Figure 2.19 Bus connection for processor , keyboard, and display . 6 Move #LOC,R0 READ TestBit Branch=0 MoveByte #3,INSTATUS READ DATAIN,(R0) ECHO TestBit Branch=0 MoveByte #3,OUTSTATUS ECHO (R0),DATAOUT Compare #CR,(R0)+ Branch0 READ Initialize pointer registerR0 to point to the addressof the first locationin memory wherethe charactersare to be stored. Wait for a characterto be entered in the keyboard buffer DATAIN. Transferthe characterfrom DATAIN into the memory(this clears SIN to 0). Wait for the display to becomeready. Move thecharacterjust read to the display buffer register(this clearsSOUT to 0). Check if the characterjust read is CR (carriagereturn). If it is not CR, then branch back and read anothercharacter. Also, increment the pointer to store the next character. Figure 2.20. A program that reads a line of characters and displays it. 7 0 Stack pointer register SP • • • - 28 Current top element 17 739 Stack BOTTOM 2k - 1 • • • 43 Bottom element • • • Figure 2.21. A stack of words in the memory. 8 SP 19 - 28 17 739 - 28 17 739 SP Stack NEWITEM • • • • • • 43 43 19 (a) After push from NEWITEM ITEM - 28 (b) After pop into ITEM Figure 2.22. Effect of stack operations on the stack in Figure 2.21. 9 SAFEPOP Compare Branch> 0 #2000,SP EMPTYERROR Move (SP)+,ITEM Check to seeif the stack pointer contains an addressvaluegreaterthan 2000. If it does,the stack is empty . Branch to the routine EMPTYERROR for appropriate action. Otherwise,pop the top of the stack into memory location ITEM. (a) Routine for a safe pop operation SAFEPUSH Compare Branch 0 #1500,SP FULLERROR Move NEWITEM, – (SP) Check to seeif the stack pointer contains an addressvalueequal to or less than 1500. If it does, the stack is full. Branch to the routine FULLERROR for appropriateaction. Otherwise,push the element in memory location NEWITEM onto the stack. (b) Routine for a safe push operation Figure 2.23. Checking for empty and full errors in pop and push operations. 10 Memory location Memory location Calling program 200 204 Call SUB next instruction Subroutine SUB 1000 first instruction Return 1000 PC 204 Link 204 Call Return Figure 2.24. Subroutine linkage using a link register. 11