1 / 38

IA32 (Pentium) Processor Architecture

IA32 (Pentium) Processor Architecture. Processor modes:. Protected (mode we will study) 32-bit mode 32-bit (4GB) address space Virtual 8086 modes Real mode 1MB address space System management mode. Registers. 32-bit GPR’s (“general” purpose registers): eax ebp ebx esp

shiloh
Download Presentation

IA32 (Pentium) Processor Architecture

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. IA32 (Pentium) Processor Architecture

  2. Processor modes: • Protected (mode we will study) • 32-bit mode • 32-bit (4GB) address space • Virtual 8086 modes • Real mode • 1MB address space • System management mode

  3. Registers • 32-bit GPR’s (“general” purpose registers): eax ebp ebx esp ecx esi edx edi eflags eip

  4. Registers e[a,b,c,d]x: 32 bits 16 bits 8 bits Note: eax is one register that can be viewed four different ways. (It is not four different registers. Schizophrenic?) 31 eax 0 15 ax 0 7 ah 0 7 al 0

  5. Registers • Not really GPR’s. • eax - accumulator; multiplication and division • ecx - loop counter • esp - stack pointers; don’t use • esi, edi - for memory-to-memory transfer • ebp - used by HLL for local vars on stack

  6. Registers • Additional registers: • 16-bit segment registers • cs, es, ss, fs, ds, gs • don’t use • eip • instruction pointer / program counter (PC) • don‘t use

  7. Registers • Additional registers: • eflags • contains results of operations • 32 individual bits • control flags • status flags: • C = carry (unsigned) • O = overflow (signed); also called V • S = sign; also called N for negative • Z = zero

  8. Registers • Additional registers: • floating point registers: • ST(0) … ST(7) • MMX has 8 64-bit regs • XMM has 8 128-bit regs

  9. Fundamental instructions • mov - move • add - addition • sub - subtraction • call - call a function • ret - return from a function to caller

  10. Fundamental instructions • In all of the following examples, let: K equ 12 a constant (doesn’t use memory) a dword 52 a variable (uses memory)

  11. Fundamental instructions Mov (MOVE)

  12. Fundamental instructions • mov - move • destination = source mov dst, src

  13. From IA-32 Intel Architecture Software Developer’s Manual, Volume 2A: Instruction Set Reference A-M

  14. mov mov r32, r/m32 Ex. movebx, ecx Ex. movebx, a mov r/m32, r32 Ex. movecx, ebx Ex. mov a, ebx mov r32, imm32 Ex. movebx, K mov r/m32, imm32 Ex. moveax, K Ex. mov a, K

  15. mov notes mov r32, r/m32 Ex. movebx, ecx Ex. movebx, a mov r/m32, r32 Ex. movecx, ebx Ex. mov a, ebx mov r32, imm32 Ex. movebx, K mov r/m32, imm32 Ex. moveax, K Ex. mov a, K • Note the duplication: mov eax, ebx appear 2x mov eax, K appears 2x. • Note: No mov m32, m32. • Note: No imm32, imm32. Why not? • Flags affected: None. • Will mov eax, 0 affect the Z flag?

  16. Problem: swap • Swap the contents of memory location A with the contents of memory location B (and vice versa). • Assume that A and B are dwords that are already defined for you.

  17. Fundamental instructions ADD

  18. Fundamental instructions • add – addition • Two add instructions (add and add w/ carry): • add dst, src dst = dst + src • adc dst, src dst = dst + src + CF • We will only use add.

  19. From IA-32 Intel Architecture Software Developer’s Manual, Volume 2A: Instruction Set Reference A-M (advanced)

  20. add add eax, imm32 Ex. add eax, K add r/m32, imm32 Ex. add ebx, K Ex. add a, K add r/m32, r32 Ex. add ebx, ecx Ex. add a, ecx add r32, r/m32 Ex. add ebx, ecx Ex. add ebx, a

  21. add notes add eax, imm32 Ex. add eax, K add r/m32, imm32 Ex. add ebx, K Ex. add a, K add r/m32, r32 Ex. add ebx, ecx Ex. add a, ecx add r32, r/m32 Ex. add ebx, ecx Ex. add ebx, a • Remember: eax is the accumulator. • Note the duplication. • Note: No add m32, m32. • Flags affected: O, S, Z, C • Would you call this a load/store architecture?

  22. Problem: add ‘em up • You are given 3 dwords, A, B, and C that have been previously assigned values. • Add them up and save the result in a dword called SUM.

  23. Fundamental instructions sub

  24. Fundamental instructions • sub – subtraction • Like add, there are two subtract instructions, sub, and subtract w/ borrow: • sub dst, src dst = dst - src • sbb dst, src dst = dst – (src + CF) • We will only use sub.

  25. From IA-32 Intel Architecture Software Developer’s Manual, Volume 2B: Instruction Set Reference N-Z (advanced)

  26. sub sub eax, imm32 Ex. sub eax, K sub r/m32, imm32 Ex. sub ebx, K Ex. sub a, K sub r/m32, r32 Ex. sub ebx, ecx Ex. sub a, ecx sub r32, r/m32 Ex. sub ebx, ecx Ex. sub ebx, a

  27. sub notes sub eax, imm32 Ex. sub eax, K sub r/m32, imm32 Ex. sub ebx, K Ex. sub a, K sub r/m32, r32 Ex. sub ebx, ecx Ex. sub a, ecx sub r32, r/m32 Ex. sub ebx, ecx Ex. sub ebx, a • Remember: eax is the accumulator. • Note the duplication. • Note: No sub m32, m32. • Flags affected: O, S, Z, C • Would you call this a load/store architecture?

  28. Problem: subtract ‘em • You are given 3 dwords, A, B, and C that have been previously assigned values. • Subtract one from the first, two from the second, and ten from the third. • Would your solution still work if this were a load/store architecture?

  29. Fundamental instructions CALL

  30. Fundamental instructions • call - call a function (AKA subroutine, routine, procedure) • Use registers or stack to pass arguments to function. • Use registers to return value from function. • Ex. mov eax, 0 ;input param to function f is 0 in eax call f ;call our function mov ebx, eax ;save value returned for future use

  31. Fundamental instructions • Windows calling conventions: • Always assume that all flags are affected. • 32-bit Windows calling conventions: • EBX, ESI, and EDI are always preserved by called function. • EAX, ECX, and EDX can be freely modified (by called function).

  32. From IA-32 Intel Architecture Software Developer’s Manual, Volume 2A: Instruction Set Reference A-M

  33. Call example • The dump function can be called at any time by your program to display the contents of registers (including the EFLAGS register). • Unlike other Windows functions, it preserves all of the caller’s registers.

  34. Call example ;---------------------------------------------------------------------- align 4 .code ;insert executable instructions below main PROC ;program execution begins here mov eax, 1 ;set regs values mov ebx, 2 mov ecx, 3 mov edx, 4 mov esi, 5 mov edi, 6 call dump ;show contents of regs mov eax, input(prompt) ;prompt the user exit ;end of program main ENDP

  35. Call example ;---------------------------------------------------------------------- align 4 .code ;insert executable instructions below main PROC ;program execution begins here moveax, 1 ;set regs values movebx, 2 movecx, 3 movedx, 4 movesi, 5 movedi, 6 call dump ;show contents of regs moveax, input(prompt) ;prompt the user exit ;end of program main ENDP

  36. ret • Return from procedure (AKA function, method, routine, or subroutine). • Flags affected: none.

  37. Problems: • One way to pass (and return) arguments to functions is to use registers. • Write a function that doubles a number. • The number to be doubled is in eax. • The result should also be in eax. • Write a function that adds three numbers together.

More Related