38
IA32 (Pentium) Processor Architecture

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

Embed Size (px)

Citation preview

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

IA32 (Pentium) Processor Architecture

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

Processor modes:

1. Protected (mode we will study)– 32-bit mode– 32-bit (4GB) address space

2. Virtual 8086 modes3. Real mode– 1MB address space

4. System management mode

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

Registers

• 32-bit GPR’s (“general” purpose registers):

eax ebpebx especx esiedx edieflags eip

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

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

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

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

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

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

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

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

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

Registers

• Additional registers:– floating point registers:• ST(0) … ST(7)

– MMX has 8 64-bit regs

– XMM has 8 128-bit regs

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

Fundamental instructions

1. mov - move

2. add - addition

3. sub - subtraction

4. call - call a function

5. ret - return from a function to caller

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

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)

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

MOV (MOVE)Fundamental instructions

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

Fundamental instructions

• mov - move– destination = source

mov dst, src

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

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

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

mov

mov r32, r/m32Ex. mov ebx, ecxEx. mov ebx, a

mov r/m32, r32Ex. mov ecx, ebxEx. mov a, ebx

mov r32, imm32Ex. mov ebx, K

mov r/m32, imm32Ex. mov eax, KEx. mov a, K

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

mov notes

mov r32, r/m32Ex. mov ebx, ecxEx. mov ebx, a

mov r/m32, r32Ex. mov ecx, ebxEx. mov a, ebx

mov r32, imm32Ex. mov ebx, K

mov r/m32, imm32Ex. mov eax, KEx. mov a, K

• Note the duplication:mov eax, ebx appear 2xmov 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?

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

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.

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

ADDFundamental instructions

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

Fundamental instructions

• add – addition– Two add instructions (add and add w/ carry):• add dst, src

dst = dst + src

• adc dst, srcdst = dst + src + CF

• We will only use add.

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

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

(advanced)

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

add

add eax, imm32Ex. add eax, K

add r/m32, imm32Ex. add ebx, KEx. add a, K

add r/m32, r32Ex. add ebx, ecxEx. add a, ecx

add r32, r/m32Ex. add ebx, ecxEx. add ebx, a

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

add notes

add eax, imm32Ex. add eax, K

add r/m32, imm32Ex. add ebx, KEx. add a, K

add r/m32, r32Ex. add ebx, ecxEx. add a, ecx

add r32, r/m32Ex. add ebx, ecxEx. 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?

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

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.

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

SUBFundamental instructions

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

Fundamental instructions

• sub – subtraction– Like add, there are two subtract instructions, sub,

and subtract w/ borrow:• sub dst, src

dst = dst - src

• sbb dst, srcdst = dst – (src + CF)

• We will only use sub.

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

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

(advanced)

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

sub

sub eax, imm32Ex. sub eax, K

sub r/m32, imm32Ex. sub ebx, KEx. sub a, K

sub r/m32, r32Ex. sub ebx, ecxEx. sub a, ecx

sub r32, r/m32Ex. sub ebx, ecxEx. sub ebx, a

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

sub notes

sub eax, imm32Ex. sub eax, K

sub r/m32, imm32Ex. sub ebx, KEx. sub a, K

sub r/m32, r32Ex. sub ebx, ecxEx. sub a, ecx

sub r32, r/m32Ex. sub ebx, ecxEx. 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?

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

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?

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

CALLFundamental instructions

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

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 functionmov ebx, eax ;save value returned for

future use

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

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

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

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

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

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.

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

Call example;----------------------------------------------------------------------

align 4.code ;insert executable instructions below

main PROC ;program execution begins heremov eax, 1 ;set regs valuesmov ebx, 2mov ecx, 3mov edx, 4mov esi, 5mov edi, 6call dump ;show contents of regsmov eax, input(prompt) ;prompt the userexit ;end of program

main ENDP

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

;----------------------------------------------------------------------align 4.code ;insert executable instructions below

main PROC ;program execution begins heremov eax, 1 ;set regs valuesmov ebx, 2mov ecx, 3mov edx, 4mov esi, 5mov edi, 6call dump ;show contents of regsmov eax, input(prompt) ;prompt the userexit ;end of program

main ENDP

Call example

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

ret

• Return from procedure (AKA function, method, routine, or subroutine).

• Flags affected: none.

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

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.