Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Pertemuan 13 Mesin IA-32 Pentium: I Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1.

Similar presentations


Presentation on theme: "1 Pertemuan 13 Mesin IA-32 Pentium: I Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1."— Presentation transcript:

1 1 Pertemuan 13 Mesin IA-32 Pentium: I Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1

2 2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Membandingkan implementasi instruksi mesin untuk Arsitektur Komputer Intel Pentium ( C4 ) ( No TIK : 6 )

3 3 Chapter 3. The IA-32 Pentium Instruction Set: I (OFC3)

4 4

5 5 Figure 3.38.Compatibility of the IA-32 register structure with earlier Intel processor register structures.

6 = displacement 1000 doubleword 1060 Operand Figure Examples of addressing modes in the IA-32 architecture. Main memory address Base register EBP Operand address (EA) = [EBP] + 60 (a) Base with displacement mode, expressed as [EBP + 60] = displacement Operand Base register EBP Operand address (EA) = [EBP] + [ESI]  (b) Base with displacement and index mode, expressed as [EBP + ESI * ] 1360 List of 4-byte (doubleword) data items 40 Index register ESI scale factor = = [Index register]  4 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

7 7 LEAEBX,NUM1Initializebase(EBX)and MOVECX,Ncounter(ECX)registers. MOVEAX,0Clearaccumulator(EAX) MOVEDI,0andindex(EDI)registers. STARTADD:ADDEAX,[EBX+EDI4]AddnextnumberintoEAX. INCEDIIncrementindexregister. DECECXDecrementcounterregister. JGSTARTADDBranchbackif[ECX]>0. MOVSUM,EAXStoresuminmemory. (a) Straightforward approach LEAEBX,NUM1LoadbaseregisterEBXand SUBEBX,4adjusttoholdNUM14. MOVECX,NInitializecounter/index(ECX). MOVEAX,0Cleartheaccumulator(EAX). STARTADD:ADDEAX,[EBX+ECX4]AddnextnumberintoEAX. LOOPSTARTADDDecrementECXandbranch backif[ECX]>0. MOVSUM,EAXStoresuminmemory. (b) More compact program Figure IA-32 program for adding numbers. * * –

8 8

9 9 Assemblerdirectives.data NUM1DD17,3,  51,242, 113 NDD5 SUMDD0.code Statementsthatgenerate machineinstructions MAIN:LEAEBX,NUM1 SUBEBX,4 MOVECX,N MOVEAX,0 STARTADD :ADDEAX,[EBX+ECX4] LOOPSTARTADD MOVSUM,EAX AssemblerdirectiveENDMAIN Figure Complete IA-32 assembly language representation for the program in Figure 3.40b. * 

10 10 LEAEBP,LOCEBPpointstofirstbyte. MOVAL,[EBP]LoadfirstbyteintoAL. SHLAL,4Shiftleftby4bitpositions. MOVBL,[EBP+1]LoadsecondbyteintoBL. ANDBL,0FHClearhigh-order4bitstozero. ORAL,BLConcatenatetheBCDdigits. MOVPACKED,ALStoretheresult. Figure An IA-32 routine to pack two BCD digits into a byte.

11 11 LEAEBP,LOCEBPpointstomemoryarea. READ:BTINSTATUS,3Waitforcharactertobe JNCREADenteredintoDATAIN. MOVAL,DATAINTransfercharacterintoAL. MOV[EBP],ALStorethecharacterinmemory INCEBPandincrementpointer. ECHO:BTOUTSTATUS,3Waitfordisplayto JNCECHObeready. MOVDATAOUT,ALSendcharactertodisplay. CMPAL,CRIfnotcarriagereturn, JNEREADreadmorecharacters. Figure An IA-32 program that reads a line of characters and displays it.

12 12 Pertemuan 14 Mesin IA-32 Pentium: II Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1

13 13 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Membandingkan implementasi instruksi mesin untuk Arsitektur Komputer Intel Pentium ( C4 ) ( No TIK : 6 )

14 14 Chapter 3. The IA-32 Pentium Instruction Set: II (OFC4)

15 15 Callingprogram... LEAEBX,NUM1Loadparameters MOVECX,NintoEBX,ECX. CALLLISTADDBranchtosubroutine. MOVSUM,EAXStoresumintomemory.... Subroutine LISTADD:PUSHEDISaveEDI. MOVEDI,0UseEDIasindexregister. MOVEAX,0UseEAXasaccumulatorregister. STARTADD:ADDEAX,[EBX+EDI4]Addnextnumber. INCEDIIncrementindex. DECECXDecrementcounter. JGSTARTADDBranchbackif[ECX]>0. POPEDIRestoreEDI. RETBranchbacktoCallingprogram. (a) Calling program and subroutine ESP [EDI] ReturnAddress OldTOS (b) Stack contents after saving EDI in subroutine Figure 3.45.Program of Figure 3.40a written as an IA-32 subroutine; parameters passed through registers. * 

16 16 (Assumetopofstackisatlevel1below.) Callingprogram PUSHOFFSETNUM1Pushparametersontothestack. PUSHN CALLLISTADDBranchtothesubroutine. ADDESP,4Removenfromthestack. POPSUMPopthesumintoSUM.... Subroutine LISTADD:PUSHEDISaveEDIanduse MOVEDI,0asindexregister. PUSHEAXSaveEAXanduseas MOVEAX,0accummulator register. PUSHEBXSaveEBXandload MOVEBX,[ESP+20]addressNUM1. PUSHECXSaveECXand MOVECX,[ESP+20]loadcountn. STARTADD:ADDEAX,[EBX+EDI4]Addnextnumber. INCEDIIncrementindex. DECECXDecrementcounter. JGSTARTADDBranchbackifnotdone. MOV[ESP+24],EAXOverwriteNUM1instackwithsum. POPECXRestoreregisters. POPEBX POPEAX POPEDI RETReturn. (a) Calling program and subroutine [ECX] [EBX] [EAX] [EDI] ReturnAddress n NUM1 Level3 Level2 Level1 (b) Stack contents at different times Figure Program of Figure 3.40a written as an IA-32 subroutine; parameters passed on the stack. *   

17 17 AddressInstructionsComments Callingprogram PUSHPARAM2Placeparameters 2006PUSHPARAM1onstack. 2012CALLSUB1 2017POPRESULTStoreresult. ADDESP,4Restorestacklevel.... Firstsubroutine 2100SUB1:PUSHEBPSaveframepointerregister. MOVEBP,ESPLoadframepointer. PUSHEAXSaveregisters. PUSHEBX PUSHECX PUSHEDX MOVEAX,[EBP+8]Getfirstparameter. MOVEBX,[EBP+12]Getsecondparameter.... PUSHPARAM3Placeparameteronstack. 2160CALLSUB2 2165POPECXPopSUB2resultintoECX.... MOV[EBP+8],EDXPlaceansweronstack. POPEDXRestoreregisters. POPECX POPEBX POPEAX POPEBPRestoreframepointerregister. RETReturntoMainprogram. Secondsubroutine 3000SUB2:PUSHEBPSaveframepointerregister. MOVEBP,ESPLoadframepointer. PUSHEAXSaveregisters. PUSHEBX MOVEAX,[EBP+8]Getparameter.... MOV[EBP+8],EBXPlaceSUB2resultonstack. POPEBXRestoreregisters. POPEAX POPEBPRestoreframepointerregister. RETReturntofirstsubroutine. Figure Nested subroutines in IA-32 assembly language.

18 18

19 19 LEAEBP,AVECEBPpointstovectorA. LEAEBX,BVECEBXpointstovectorB. MOVECX,NECXistheloopcounter. MOVEAX,0EAXaccumulatesthedotproduct. MOVEDI,0EDIisanindexregister. LOOPSTART:MOVEDX,[EBP+EDI4]Computetheproduct IMULEDX,[EBX+EDI4]ofnextcomponents. INCEDIIncrementindex. ADDEAX,EDXAddtoprevioussum. LOOPLOOPSTARTBranchbackifnotdone. MOVDOTPROD,EAXStoredotproductinmemory. Figure IA-32 dot product program. * *

20 20 for (j=n1;j>0;j=j1) { for (k=j1;k>=0;k=k1) { if (LIST[k]>LIST[j]) {TEMP=LIST[k]; LIST[k]= j]; LIST[j]=TEMP; } } } (a) C-language program for sorting LEAEAX,LISTLoadlistpointerbase MOVEDI,Nregister(EAX),andinitialize DECEDIouterloopindexregister (EDI)toj=n1. OUTER:MOVECX,EDIInitializeinnerloopindex DECECXregister(ECX)tok=j1. MOVDL,[EAX+EDI]LoadLIST(j)intoregisterDL. INNER:CMP[EAX+ECX],DLCompareLIST(k)toLIST(j). JLENEXTIfLIST(k)LIST(j),goto nextlowerkindexentry; XCHG[EAX+ECX],DLOtherwise,interchangeLIST(k) andLIST(j),leaving MOV[EAX+EDI],DLnewLIST(j)inDL. NEXT:DECECXDecrementinnerloopindexk. JGEINNERRepeatorterminateinnerloop. DECEDIDecrementouterloopindexj. JGOUTERRepeatorterminateouterloop. (b) IA-32 program implementation Figure An IA-32 byte-sorting program using straight-selection sort. – – –– – – 

21 21 Subroutine INSERTION:MOVRNEWID,[RNEWREC] CMPRHEAD,0Checkiflistempty. JGHEAD MOVRHEAD,RNEWRECIfyes,newrecordbecomes RETone-entrylist. HEAD:CMPRNEWID,[RHEAD]Checkifnewrecord becomeshead. JGSEARCH MOV[RNEWREC+4],RHEADIfyes,makenewrecord MOVRHEAD,RNEWRECthehead. RET SEARCH:MOVRCURRENT,RHEADOtherwise,use LOOPSTART:MOVRNEXT,[RCURRENT+4]RCURRENT CMPRNEXT,0andRNEXT JETAILtomovethrough CMPRNEWID,[RNEXT]thelisttofind JLINSERTtheinsertionpoint. MOVRCURRENT,RNEXT JMPLOOPSTART INSERT:MOV[RNEWREC+4],RNEXT TAIL:MOV[RCURRENT+4],RNEWREC RET Figure An IA-32 subroutine for inserting a new record into a linked list.

22 22 Subroutine DELETION:CMPRIDNUM,[RHEAD]Checkifhead. JGTSEARCH MOVRHEAD,[RHEAD+4]Ifyes,remove. RET SEARCH:MOVRCURRENT,RHEADOtherwise, LOOPSTART:MOVRNEXT,[RCURRENT+4]useRCURRENT CMPRIDNUM,[RNEXT]andRNEXT JEQDELETEtomovethrough MOVRCURRENT,RNEXTthelistto JMPLOOPSTARTfindtherecord. DELETE:MOVRTEMP,[RNEXT+4] MOV[RCURRENT+4],RTEMP RET Figure An IA-32 subroutine for deleting a record from a linked list.

23 23 Program1 2 CLR.LD0MOVE.W#$FFFF,D0 MOVEA.L#LIST,A0MOVEA.L#LIST,A0 LOOPMOVE.W(A0)+,D1LOOPLSL.W(A0)+ BGELOOPBCCLOOP ADDQ.L#1,D0LSL.W#1,D0 CMPI#17,D0BCSLOOP BLTLOOPMOVE.W2(A0),RSLT MOVE.W2(A0),RSLT Figure P3.1. Two programs for Problem – –

24 24 Table3.3 IA-32 addressing modes NameAssemblersyntaxAddressingfunction ImmediateValueOperand=Value DirectLocationEA=Location RegisterRegEA=Reg thatis,Operand=[Reg] Registerindirect[Reg]EA=[Reg] Basewith[Reg+Disp]EA=[Reg]+Disp displacement Indexwith[Reg S+Disp] EA=[Reg]S+Disp displacement Basewithindex[Reg1+Reg2S]EA=[Reg1]+[Reg2]S Basewithindex[Reg1+Reg2S+Disp]EA=[Reg1]+[Reg2]S+Disp anddisplacement Value=an8-or32-bitsignednumber Location=a32-bitaddress Reg,Reg1,Reg2=oneofthegeneralpurposeregistersEAX,EBX,ECX, EDX,ESP,EBP,ESI,EDI,withtheexceptionthat ESPcannotbeusedasanindexregister Disp=an8-or32-bitsignednumber,exceptthatintheIndexwith displacementmodeitcanonlybe32bits. S=ascalefactorof1,2,4,or8 * * *   


Download ppt "1 Pertemuan 13 Mesin IA-32 Pentium: I Matakuliah: T0324 / Arsitektur dan Organisasi Komputer Tahun: 2005 Versi: 1."

Similar presentations


Ads by Google