Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 IA-32

Similar presentations


Presentation on theme: "1 IA-32"— Presentation transcript:

1 1 IA-32 http://www.pds.ewi.tudelft.nl/~iosup/Courses/2011_ti1400_6.ppt

2 TU-Delft TI1400/11-PDS 2 IA family IA (Intel Architecture) is a family of processors Each processor—same architecture, but different organization -same instruction set -different performance 32-bit memory addresses and variable length instructions Very large instruction set (not RISC) 1982 1985 1989 1993

3 TU-Delft TI1400/11-PDS 3 Floorplan IA-32

4 TU-Delft TI1400/11-PDS 4 Other Example: PowerPC Floating-point unit Integer unit Instruction unit instructions Cache main memory

5 TU-Delft TI1400/11-PDS 5 Floorplan PowerPC

6 TU-Delft TI1400/11-PDS 6 FPU Data Cache Instr. Cache Registers MMU Load/Store Unit Floorplan PowerPC

7 TU-Delft TI1400/11-PDS 7 IA-32 1.Introduction 2.Registers 3.Memory Layout 4.Instructions 5.Examples of Assembler Code for IA-32 6.Subroutines

8 TU-Delft TI1400/11-PDS 8 IA register structure FP0 FP7 floating - point registers R0 R7 general- purpose registers

9 TU-Delft TI1400/11-PDS 9 Special registers Code Segment CS Stack Segment SS DS ES FS GS Data Segments

10 TU-Delft TI1400/11-PDS 10 Status Register OFIF 31131211 0 Status Register CFTFSFZF 6789 CFCarry ZFZero SFSign IOPLI/O privilege level OFOverflow IFInterrupt enable IOPL

11 TU-Delft TI1400/11-PDS 11 Register Naming R0EAX R1EBX R2ECX R3EDX R4 ESP R5 EBP R6 ESI R7 EDI EIP EFLAGS Data registers Pointer registers Index registers Instruction Pointer Status Register

12 TU-Delft TI1400/11-PDS 12 IA-32 1.Introduction 2.Registers 3.Memory Layout 4.Instructions 5.Examples of Assembler Code for IA-32 6.Subroutines

13 TU-Delft TI1400/11-PDS 13 Memory Memory is byte addressable Doublewords can start at any byte location Data Operands are 8 or 32 bits wide Mode is little-endian scheme (vs big-endian PowerPC)

14 TU-Delft TI1400/11-PDS 14 Addressable data units byte 3byte 0 310Bit Byte Doubleword 0

15 TU-Delft TI1400/11-PDS 15 IA-32 1.Introduction 2.Registers 3.Memory Layout 4.Instructions 5.Examples of Assembler Code for IA-32 6.Subroutines

16 TU-Delft TI1400/11-PDS 16 Instructions Variable length instructions 1-12 bytes Five type of instructions -Copy instructions (MOV) -Arithmetic and logic instructions -Flow control -Processor control instructions -I/O instructions Format: INSTR Rdst,Rsrc

17 TU-Delft TI1400/11-PDS 17 Instruction Format OpcodeAddressingDisplacementImmediate 1 or 2 bytes 1 or 4 bytes variable opcode length

18 TU-Delft TI1400/11-PDS 18 Addressing modes Many addressing modes: -Immediatevalue -DirectM(value) -Register[reg] -Register IndirectM([reg]) -Base with displacementM([reg]) +Disp -Index with displacementM([reg]  S +Disp) -Base with indexM([reg1]+[reg2]  S) -Base with index and M([reg1]+[reg2]  S+Disp) displacement S=1,2,4 or 8Disp= 8 or 32-bit signed number

19 TU-Delft TI1400/11-PDS 19 Immediate and Direct Immediate MOV EAX, 25 [EAX]  #25 MOV EAX, 3FA00H [EAX]  # 3FA00H Direct MOV EAX, loc [EAX]  M(loc) or MOV EAX, [loc] [EAX]  M(loc)

20 TU-Delft TI1400/11-PDS 20 Register indirect Register MOV EBX,OFFSET loc [EBX]  #loc or LEA EBX,loc [EBX]  #loc Register indirect MOV EAX,[EBX] [EAX]  M(EBX)

21 TU-Delft TI1400/11-PDS 21 Base with Index and Displacement MOV EAX,[EBP+ESI*4+200] EAX  M([EBP] + [ESI]*4 + #200) Operand 1000 40 EBP ESI 1000 1200 1360

22 TU-Delft TI1400/11-PDS 22 Arithmetic instructions May have one or two operands ADD dst,scr meaning [dst]  [dst] + [src]

23 TU-Delft TI1400/11-PDS 23 Compare Used to compare values and leave register contents unchanged CMPdst, src[dst] - [src]

24 TU-Delft TI1400/11-PDS 24 Flow control Two basic branch instructions: JMP[loc]Branch unconditionally JG, JZ, JS, etc Branch if condition is satisfied

25 TU-Delft TI1400/11-PDS 25 IA-32 1.Introduction 2.Registers 3.Memory Layout 4.Instructions 5.Examples of Assembler Code for IA-32 6.Subroutines

26 TU-Delft TI1400/11-PDS 26 Summation example LEAEBX, NUM1[EBX]  #NUM1 MOVECX, N[EXC]  M(N) MOVEAX, 0[EAX]  #0 MOVEDI, 0[EDI]  #0 L:ADDEAX, [EBX+EDI*4]Add next number to EAX INCEDI[EDI]  [EDI] +1 DECECX[ECX]  [ECX] -1 JGLBranch if [ECX]>0 MOVSUM, EAXM(SUM)  [EAX]

27 TU-Delft TI1400/11-PDS 27 Sorting example int[] listarray = new list[n]; int temp; for(j=n-1, j>0, j--){ for(k=j-1, k>=0, k--){ if(list[j] > list[k]) { temp = list[k]; list[k] = list[j]; list[j] = temp; }

28 TU-Delft TI1400/11-PDS 28 Assembler code LEAEAX, list[EAX]  #list MOVEDI, N[EDI]  n DECEDI [EDI]  n-1 init(j) outer:MOVECX, EDI[ECX]  j DECECX [ECX]  j-1 init (k) MOVDL, [EAX+EDI]load list(j) into DL inner:CMP[EAX+ECX], DLcompare list(k) to list(j) JLEnextif list(j) >= list(k) XCNG[EAX+ECX], DLswap MOV[EAX+ECX], DL new list(j) in DL next:DECECXdecrement k JGEinnerrepeat or terminate DECEDIdecrement j JGEouterrepeat or terminate

29 TU-Delft TI1400/11-PDS 29 Question Why is this assembler program an incorrect translation of the Java program?

30 TU-Delft TI1400/11-PDS 30 IA-32 1.Introduction 2.Registers 3.Memory Layout 4.Instructions 5.Examples of Assembler Code for IA-32 6.Subroutines  really long

31 TU-Delft TI1400/11-PDS 31 Subroutines CALL sub Return address is saved on stack (ESP register) Return is RET [EIP]  #sub [EIP]  [ESP] [ESP]  [ESP]+4

32 TU-Delft TI1400/11-PDS 32 Stack instructions ESP register is used as stack pointer PUSH src [ESP]  [ESP] - #4 M([ESP])  [src] POP dst [dst]  M([ESP]) [ESP]  [ESP] + #4 PUSHAD (POPAD) push (pop) all 8 registers on (from) stack

33 TU-Delft TI1400/11-PDS 33 Stack frames.... PUSH NParameter n on stack 2000CALLSub1Call subroutine at 2400........... 2004 N 10052 2400 ESP EIP 10052 Note: Sub1 starts at address 2400 Stack Pointer Stack program counter stack pointer

34 TU-Delft TI1400/11-PDS 34 Subroutine Sub1 Sub1:PUSHEAXSave EAX PUSHEBXSave EBX MOVEAX, [EDI + 12]n to EAX DECEAX.... PUSHEAXLoad n-1 on stack L:CALLSub2Call subroutine POPNPut result in M(N) POPEBXRestore EBX POPEAXRestore EAX RETreturn

35 TU-Delft TI1400/11-PDS 35 Stack frame in Sub1 [EBX] [EAX] Return Address n 10036 ? ESP EIP 10052 Stack frame at arrow 10036 2400:PUSHEAX PUSHEBX MOVEAX, [EDI + 12] DECEAX Q What is the value op EIP? After PUSH EBX

36 TU-Delft TI1400/11-PDS 36 Subroutine Sub1 2400PUSHEAXSave EAX PUSHEBXSave EBX MOVEAX, [EDI + 12]n to EAX DECEAX.... PUSHEAXLoad n-1 on stack L:CALLSub2Call subroutine POPNPut result in M(N) POPEBXRestore EBX POPEAXRestore EAX RETreturn After DEC EAX

37 TU-Delft TI1400/11-PDS 37 Stack frame in Sub1 Stack frame at arrow [EBX] [EAX] Return Address n 10036 ? EIP 10052 10036 n-1 EAX ESP 2400:PUSHEAX PUSHEBX MOVEAX, [EDI + 12] DECEAX After DEC EAX

38 TU-Delft TI1400/11-PDS 38 Subroutine Sub1 2400:PUSHEAXSave EAX PUSHEBXSave EBX MOVEAX, [EDI + 12]n to EAX DECEAX.... PUSHEAXLoad n-1 on stack L:CALLSub2Call subroutine POPNPut result in M(N) POPEBXRestore EBX POPEAXRestore EAX RETreturn After PUSH EAX

39 TU-Delft TI1400/11-PDS 39 Stack frame in Sub1 Stack frame at arrow n-1 [EBX] [EAX] Return Address n 10032 ? EIP 10052 10036 n-1 EAX ESP 2400:PUSHEAX PUSHEBX MOVEAX, [EDI + 12] DECEAX.... PUSHEAX After PUSH EAX

40 TU-Delft TI1400/11-PDS 40 Stack frame in Sub2 Stack frame at arrow Return Address n-1 [EBX] [EAX] Return Address n 10028 ? EIP 10052 10036 n-2 EAX ESP Sub2:MOVEAX, [EDI+4] DECEAX MOV[EDI+4], EAX RET After DEC EAX

41 TU-Delft TI1400/11-PDS 41 Stack frame in Sub2 Stack frame at arrow Return Address n-2 [EBX] [EAX] Return Address n 10028 ? EIP 10052 10036 n-2 EAX ESP Sub2:MOVEAX, [EDI+4] DECEAX MOV[EDI+4], EAX RET After MOV…


Download ppt "1 IA-32"

Similar presentations


Ads by Google