Presentation is loading. Please wait.

Presentation is loading. Please wait.

IA32 (Pentium) Processor Architecture. Processor modes: 1.Protected (mode we will study) – 32-bit mode – 32-bit (4GB) address space 2.Virtual 8086 modes.

Similar presentations


Presentation on theme: "IA32 (Pentium) Processor Architecture. Processor modes: 1.Protected (mode we will study) – 32-bit mode – 32-bit (4GB) address space 2.Virtual 8086 modes."— Presentation transcript:

1 IA32 (Pentium) Processor Architecture

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

3 Registers 32-bit GPR’s (“general” purpose registers): eaxebp ebxesp ecxesi edxedi eflagseip

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

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

10 Fundamental instructions 1.mov- move 2.add- addition 3.sub- subtraction 4.call- call a function 5.ret- return from a function to caller

11 Fundamental instructions In all of the following examples, let: Kequ12  a constant (doesn’t use memory) adword52  a variable (uses memory)

12 MOV (MOVE) Fundamental instructions

13 mov - move – destination = source movdst, src

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

15 mov movr32, r/m32 Ex.movebx, ecx Ex.movebx, a movr/m32, r32 Ex.movecx, ebx Ex.mova, ebx movr32, imm32 Ex.movebx, K movr/m32, imm32 Ex.moveax, K Ex.mova, K

16 mov notes movr32, r/m32 Ex.movebx, ecx Ex.movebx, a movr/m32, r32 Ex.movecx, ebx Ex.mova, ebx movr32, imm32 Ex.movebx, K movr/m32, imm32 Ex.moveax, K Ex.mova, 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?

17 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.

18 ADD Fundamental instructions

19 add – addition – Two add instructions (add and add w/ carry): adddst, src dst = dst + src adcdst, src dst = dst + src + CF We will only use add.

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

21 add addeax, imm32 Ex.addeax, K addr/m32, imm32 Ex.addebx, K Ex.adda, K addr/m32, r32 Ex.addebx, ecx Ex.adda, ecx addr32, r/m32 Ex.addebx, ecx Ex.addebx, a

22 add notes addeax, imm32 Ex.addeax, K addr/m32, imm32 Ex.addebx, K Ex.adda, K addr/m32, r32 Ex.addebx, ecx Ex.adda, ecx addr32, r/m32 Ex.addebx, ecx Ex.addebx, 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?

23 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.

24 SUB Fundamental instructions

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

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

27 sub subeax, imm32 Ex.subeax, K subr/m32, imm32 Ex.subebx, K Ex.suba, K subr/m32, r32 Ex.subebx, ecx Ex.suba, ecx subr32, r/m32 Ex.subebx, ecx Ex.subebx, a

28 sub notes subeax, imm32 Ex.subeax, K subr/m32, imm32 Ex.subebx, K Ex.suba, K subr/m32, r32 Ex.subebx, ecx Ex.suba, ecx subr32, r/m32 Ex.subebx, ecx Ex.subebx, 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?

29 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?

30 CALL Fundamental instructions

31 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. moveax, 0;input param to function f is 0 in eax callf;call our function movebx, eax;save value returned for future use

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

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

34 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.

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

36 ;---------------------------------------------------------------------- align4.code;insert executable instructions below mainPROC;program execution begins here moveax, 1;set regs values movebx, 2 movecx, 3 movedx, 4 movesi, 5 movedi, 6 calldump;show contents of regs moveax, input(prompt);prompt the user exit;end of program mainENDP Call example

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

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


Download ppt "IA32 (Pentium) Processor Architecture. Processor modes: 1.Protected (mode we will study) – 32-bit mode – 32-bit (4GB) address space 2.Virtual 8086 modes."

Similar presentations


Ads by Google