Chapter 4
Chapter 4
Chapter 4
THE CENTRAL
PROCESSING UNIT
Language levels
High-Level Languages
Characteristics
Portable : to varying
degrees
Complex:one statement
can do much work
Expressive
Human readable
1
02/03/2019
Machine languages
Characteristics
Not portable : specific to
hardware
Simple : each instruction
does a simple task
Not expressive : each
instruction performs little
work
Not human readable :
requires losts of effort,
requires tool support
Assembly languages
Characteristics
Not portable : each
assembly language
instruction map to one
machine language
instruction
Simple : each
instruction does a
simple task
Not expressive
Human readable
2
02/03/2019
Pros
X86-64 is popular
CourseLab computers are x86-64 computers
Program natively on CourseLab instead of using an emulator
Cons
X86-64 assembly language is big
Each instruction is simple, but…
There are many instructions
Instructions differ widely
3
02/03/2019
Includes
CPU : CU, ALU,
Registers
Memory : RAM
RAM
4
02/03/2019
Intel Microprocessors
5
02/03/2019
6
02/03/2019
7
02/03/2019
64-bit Processors
Intel64
64-bit linear address space
Intel: Pentium Extreme, Xeon, Celeron D, Pendium D,
Core 2, and Core i7
IA-32e Mode
Compatibility mode for legacy 16- and 32-bit
applications
64-bit Mode uses 64-bit addresses and operands
8
02/03/2019
General-Purpose Registers
Used primarily for arithmetic and data movement
mov eax, 10 move constant 10 into register eax
Specialized uses of Registers
EAX – Accumulator register
Automatically used by multiplication and division instructions
ECX – Counter register
Automatically used by LOOP instructions
ESP – Stack Pointer register
Used by PUSH and POP instructions, points to top of stack
ESI and EDI – Source Index and Destination Index register
Used by string instructions
EBP – Base Pointer register
Used to reference parameters and local variables on the stack
9
02/03/2019
10
02/03/2019
EFLAGS Register
Status Flags
Status of arithmetic and logical operations
Control and System flags
Control the CPU operation
Programs can set and clear individual bits in the EFLAGS
register
11
02/03/2019
Status Flags
Carry Flag
Set when unsigned arithmetic result is out of range
Overflow Flag
Set when signed arithmetic result is out of range
Sign Flag
Copy of sign bit, set when result is negative
Zero Flag
Set when result is zero
Auxiliary Carry Flag
Set when there is a carry from bit 3 to bit 4
Parity Flag
Set when parity is even
Least-significant byte in result contains even number of 1s
12
02/03/2019
X86 – 64 Registers
13
02/03/2019
14
02/03/2019
RSP Register
15
02/03/2019
16
02/03/2019
RIP Register
Special-purpose register…
RIP (Instruction Pointer) register
Stores the location of the next instruction
Address (in TEXT section) of machine-language instructions to be
executed next
Value changed:
Automatically to implement sequential control flow
By jump instructions to implement selection, repetition
Memory Segmentation
Memory segmentation is necessary since the 20-bits memory
addresses cannot fit in the 16-bits CPU registers
Since x86 registers are 16-bits wide, a memory segment is made of
216 consecutive words (i.e. 64K words)
Each segment has a number identifier that is also a 16-bit number
(i.e. we have segments numbered from 0 to 64K)
A memory location within a memory segment is referenced by
specifying its offset from the start of the segment. Hence the first
word in a segment has an offset of 0 while the last one has an offset
of FFFFh
To reference a memory location its logical address has to be
specified. The logical address is written as:
Segment number:offset
For example, A43F:3487h means offset 3487h within segment
A43Fh.
17
02/03/2019
Program Segments
18
02/03/2019
Segment Overlap
19
02/03/2019
20
02/03/2019
Upper 13 bits of
segment selector are
used to index the
descriptor table
TI = Table Indicator
Select the descriptor table
0 = Global Descriptor Table
1 = Local Descriptor Table
21
02/03/2019
Base Address
32-bit number that defines the starting location of the segment
32-bit Base Address + 32-bit Offset = 32-bit Linear Address
Segment Limit
20-bit number that specifies the size of the segment
The size is specified either in bytes or multiple of 4 KB pages
Using 4 KB pages, segment size can range from 4 KB to 4 GB
Access Rights
Whether the segment contains code or data
Whether the data can be read-only or read & written
Privilege level of the segment to protect its access
22
02/03/2019
Paging
23
02/03/2019
Paging – cont’d
The operating
system uses
An assembly statement
3 essentials: opcode, operands
(dest, src)
E.g.,: add a, b,c => c = a+b AT&T Syntax
Example : Example :
24
02/03/2019
25
02/03/2019
26
02/03/2019
27