1 / 24

Pertemuan 13 Mesin IA-32 Pentium: I

Pertemuan 13 Mesin IA-32 Pentium: I. Matakuliah : T0324 / Arsitektur dan Organisasi Komputer Tahun : 2005 Versi : 1. Learning Outcomes. Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu :

Télécharger la présentation

Pertemuan 13 Mesin IA-32 Pentium: I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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. Chapter 3. The IA-32 Pentium Instruction Set: I (OFC3)

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

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

  6. LEA EBX,NUM1 Initialize base (EBX) and MO V ECX,N coun ter (ECX) registers. MO V EAX,0 Clear accum ulator (EAX) MO V EDI,0 and index (EDI) registers. * ST AR T ADD: ADD EAX,[EBX + EDI 4] Add next n um b er in to EAX. INC EDI Incremen t index register. DEC ECX Decremen t coun ter register. JG ST AR T ADD Branc h bac k if [ECX] > 0. MO V SUM,EAX Store sum in memory . (a) Straightforward approach LEA EBX,NUM1 Load base register EBX and – SUB EBX,4 adjust to hold NUM1 4. MO V ECX,N Initialize coun ter/index (ECX). MO V EAX,0 Clear the accum ulator (EAX). * ST AR T ADD: ADD EAX,[EBX + ECX 4] Add next n um b er in to EAX. LOOP ST AR T ADD Decremen t ECX and branc h bac k if [ECX] > 0. MO V SUM,EAX Store sum in memory . (b) More compact program Figure 3.40. IA-32 program for adding numbers.

  7. .data NUM1 DD 17 , 3 , 51 , 242 ,  113 N DD 5 Assem bler directiv es SUM DD 0 .co de MAIN : LEA EBX , NUM1 SUB EBX , 4 MO V ECX , N Statemen ts that generate MO V EAX , 0 mac hine instructions * STARTADD : ADD EAX , [EBX +ECX 4] LOOP ST AR T ADD MO V SUM , EAX Assem bler directiv e END MAIN Figure 3.42. Complete IA-32 assembly language representation for the program in Figure 3.40b.

  8. LEA EBP ,LOC EBP p oin ts to first b yte. MO V AL,[EBP] Load first b yte in to AL. SHL AL,4 Shift left b y 4 bit p ositions. MO V BL,[EBP+1] Load second b yte in to BL. AND BL,0FH Clear high-order 4 bits to zero. OR AL,BL Concatenate the BCD digits. MO V P A CKED,AL Store the result. Figure 3.43. An IA-32 routine to pack two BCD digits into a byte.

  9. LEA EBP ,LOC EBP p oin ts to memory area. READ: BT INST A TUS,3 W ait for c haracter to b e JNC READ en tered in to D A T AIN. MO V AL,DATAIN T ransfer c haracter in to AL. MO V [EBP],AL Store the c haracter in memory INC EBP and incremen t pointer. ECHO: BT OUTST A TUS,3 W ait for displa y to JNC ECHO b e ready . MO V D A T A OUT,AL Send c haracter to displa y . CMP AL,CR If not carriage return, JNE READ read more c haracters. Figure 3.44. An IA-32 program that reads a line of characters and displays it.

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

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

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

  13. Calling program . . . LEA EBX,NUM1 Load parameters MO V ECX,N in to EBX,ECX. CALL LIST ADD Branc h to subroutine. MO V SUM,EAX Store sum in to memory . . . . Subroutine LIST ADD: PUSH EDI Sa v e EDI. MO V EDI,0 Use EDI as index register. MO V EAX,0 Use EAX as accum ulator register. * ST AR T ADD: ADD EAX, [EBX + EDI 4] Add next n um b er. INC EDI Incremen t index. DEC ECX Decremen t coun ter. JG STARTADD Branc h bac k if [ECX] > 0. POP EDI Restore EDI. RET Branc h bac k to Calling program. (a) Calling program and subroutine [EDI] ESP  Return Address Old TOS (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.

  14. (Assume top of stac k is at lev el 1 b elo w.) Calling program PUSH OFFSET NUM1 Push parameters on to the stack. PUSH N CALL LIST ADD Branc h to the subroutine. ADD ESP ,4 Remo v e n from the stack. POP SUM P op the sum in to SUM. . . . Subroutine LIST ADD: PUSH EDI Sa v e EDI and use MO V EDI,0 as index register. PUSH EAX Sa v e EAX and use as MO V EAX,0 accummulator register. PUSH EBX Sa v e EBX and load MO V EBX,[ESP+20] address NUM1. PUSH ECX Sa v e ECX and MO V ECX,[ESP+20] load count n . * ST AR T ADD: ADD EAX,[EBX+EDI 4] Add next n umber. INC EDI Incremen t index. DEC ECX Decremen t coun ter. JG ST AR T ADD Branc h bac k if not done. MO V [ESP+24],EAX Ov erwrite NUM1 in stac k with sum. POP ECX Restore registers. POP EBX POP EAX POP EDI RET Return. (a) Calling program and subroutine  [ECX] Lev el 3 [EBX] [EAX] [EDI] Return Address  Lev el 2 n NUM1  Lev el 1 (b) Stack contents at different times Figure 3.46. Program of Figure 3.40a written as an IA-32 subroutine; parameters passed on the stack.

  15. Address Instructions Commen ts Calling program . . . 2000 PUSH P ARAM2 Place parameters 2006 PUSH P ARAM1 on stac k. 2012 CALL SUB1 2017 POP RESUL T Store result. ADD ESP ,4 Restore stac k lev el. . . . First subroutine 2100 SUB1: PUSH EBP Sa v e frame p oin ter register. MO V EBP ,ESP Load frame p oin ter. PUSH EAX Sa v e registers. PUSH EBX PUSH ECX PUSH ED X MO V EAX,[EBP+8] Get first parameter. MO V EBX,[EBP+12] Get second parameter. . . . PUSH P ARAM3 Place parameter on stac k. 2160 CALL SUB2 2165 POP ECX P op SUB2 result in to ECX. . . . MO V [EBP+8],ED X Place answ er on stac k. POP ED X Restore registers. POP ECX POP EBX POP EAX POP EBP Restore frame p oin ter register. RET Return to Main program. Second subroutine 3000 SUB2: PUSH EBP Sa v e frame p oin ter register. MO V EBP ,ESP Load frame p oin ter. PUSH EAX Sa v e registers. PUSH EBX MO V EAX,[EBP+8] Get parameter. . . . MO V [EBP+8],EBX Place SUB2 result on stac k. POP EBX Restore registers. POP EAX POP EBP Restore frame p oin ter register. RET Return to first subroutine. Figure 3.47. Nested subroutines in IA-32 assembly language.

  16. LEA EBP ,A VEC EBP p oin ts to v ector A. LEA EBX,BVEC EBX p oin ts to v ector B. MO V ECX,N ECX is the lo op coun ter. MO V EAX,0 EAX accum ulates the dot pro duct. MO V EDI,0 EDI is an index register. * LOOPST AR T: MO V ED X,[EBP+EDI 4] Compute the pro duct * IMUL ED X,[EBX+EDI 4] of next comp onen ts. INC EDI Incremen t index. ADD EAX,ED X Add to previous sum. LOOP LOOPST AR T Branc h bac k if not done. MO V DOTPR OD,EAX Store dot pro duct in memory . Figure 3.49. IA-32 dot product program.

  17. – (j = n 1; j > 0; j = j 1) for – – { ( k = j 1; k > = 0; k = k 1 ) for { (LIST[ k ] > LIST[ j ]) if { TEMP = LIST[ k ]; LIST[ k ] = LIST[ j ]; LIST[ j ] = TEMP; } } } (a) C-language program for sorting LEA EAX,LIST Load list p oin ter base MO V EDI,N register (EAX), and initialize DEC EDI outer lo op index register – (EDI) to j = n 1. OUTER: MO V ECX,EDI Initialize inner lo op index – DEC ECX register (ECX) to k = j 1. MO V DL,[EAX + EDI] Load LIST(j) in to register DL. INNER: CMP [EAX + ECX],DL Compare LIST(k) to LIST(j).  JLE NEXT If LIST(k) LIST(j), go to next lo w er k index en try; X CHG [EAX + ECX],DL Otherwise, in terc hange LIST(k) and LIST(j), lea ving MO V [EAX + EDI],DL new LIST(j) in DL. NEXT: DEC ECX Decremen t inner lo op index k. JGE INNER Rep eat or terminate inner lo op. DEC EDI Decremen t outer lo op index j. JG OUTER Rep eat or terminate outer lo op. (b) IA-32 program implementation Figure 3.50. An IA-32 byte-sorting program using straight-selection sort.

  18. Subroutine INSER TION: MO V RNEWID,[RNEWREC] CMP RHEAD,0 Chec k if list empt y . JG HEAD MO V RHEAD,RNEWREC If y es, new record b ecomes RET one-en try list. HEAD: CMP RNEWID,[RHEAD] Chec k if new record b ecomes head. JG SEAR CH MO V [RNEWREC+4],RHEAD If y es, mak e new record MO V RHEAD,RNEWREC the head. RET SEAR CH: MO V R CURRENT,RHEAD Otherwise, use LOOPST AR T: MO V RNEXT,[R CURRENT+4] R CURRENT CMP RNEXT,0 and RNEXT JE T AIL to mo v e through CMP RNEWID,[RNEXT] the list to find JL INSER T the insertion p oin t. MO V R CURRENT,RNEXT JMP LOOPST AR T INSER T: MO V [RNEWREC+4],RNEXT T AIL: MO V [R CURRENT+4],RNEWREC RET Figure 3.51. An IA-32 subroutine for inserting a new record into a linked list.

  19. Subroutine DELETION: CMP RIDNUM,[RHEAD] Chec k if head. JGT SEAR CH MO V RHEAD,[RHEAD+4] If y es, remo v e. RET SEAR CH: MO V R CURRENT,RHEAD Otherwise, LOOPST AR T: MO V RNEXT,[R CURRENT+4] use R CURRENT CMP RIDNUM,[RNEXT] and RNEXT JEQ DELETE to mo v e through MO V R CURRENT,RNEXT the list to JMP LOOPST AR T find the record. DELETE: MO V R TEMP ,[RNEXT+4] MO V [R CURRENT+4],R TEMP RET Figure 3.52. An IA-32 subroutine for deleting a record from a linked list.

  20. Program 1 Program 2 CLR.L D0 MO VE.W #$FFFF,D0 MO VEA.L #LIST,A0 MO VEA.L #LIST,A0 LOOP MO VE.W (A0)+,D1 LOOP LSL.W (A0)+ BGE LOOP BCC LOOP ADDQ.L #1,D0 LSL.W #1,D0 CMPI #17,D0 BCS LOOP – BL T LOOP MO VE.W 2(A0),RSL T – MO VE.W 2(A0),RSL T Figure P3.1. Two 68000 programs for Problem 3.29.

  21. T able 3.3 IA-32 addressing modes Name Assem bler syn tax Addressing function Immediate V alue Op erand = V alue Direct Lo cation EA = Lo cation Register Reg EA = Reg that is, Op erand = [Reg] Register indirect [Reg] EA = [Reg] Base with [Reg + Disp] EA = [Reg] + Disp displacemen t  * Index with [Reg EA = [Reg] S + Disp S + Disp] displacemen t  * Base with index [Reg1 + Reg2 S] EA = [Reg1] + [Reg2] S  * Base with index [Reg1 + Reg2 S + Disp] EA = [Reg1] + [Reg2] S + Disp and displacemen t V alue = an 8- or 32-bit signed n um b er Lo cation = a 32-bit address Reg, Reg1, Reg2 = one of the general purp ose registers EAX, EBX, ECX, ED X, ESP , EBP , ESI, EDI, with the exception that ESP cannot be used as an index register Disp = an 8- or 32-bit signed n um b er, except that in the Index with displacemen t mode it can only b e 32 bits. S = a scale factor of 1, 2, 4, or 8

More Related