Professional Documents
Culture Documents
Internal Organization of A PC: Memory
Internal Organization of A PC: Memory
Memory
Control
CPU
Address Data
Expansion Bus
Peripherals
Organization of a microprocessor
CPU Control registers
Status Registers
Microprocessors
State machines that execute hardcoded instructions sequenced in assembly programs Processors perform very simple calculations
Arithmetic operations Logical operations Moving data to/from memory
Registers
On-chip storage locations made from flip-flops, very fast to access Valuable resource, not in large amounts, must be used wisely!
Cache
On-chip storage made with SRAM Enables fast access to data Not as fast as registers but faster than external memory. Cache contents are managed by the hardware.
x86 (8086)
Intel/Microsofts monopoly: cost-effective microprocessors for the mass market x86 refers to an instruction set rather than a specific processor architecture The processor core that implements the x86 instruction set has gone through substantial modifications and improvements over the last 20 years x86 is a Complex Instruction Set Computer
20,000+ instructions
Microprocessor
Busy
Idle
Busy
Busy
Idle
Busy
...
Bus
Pipelining
Fetch 1
Fetch 2
Fetch 3
Fetch 4
Store 1
Fetch 5
Fetch 6
Load 2
Fetch 7 Idle
...
Bus
Decode Decode 5 6
Decode 7
...
Exec. 1
Exec. 2
Exec. 3
Exec. 4
Idle Idle
Exec. 5
Exec. 6
Idle
Exec. 7
Memory request
Memory request
Registers
Registers are storage locations The first-level of a computers memory hierarchy The fastest to access storage in your system Purposes
Data used in arithmetic/logical operations Pointers to memory locations containing data or instructions Control information (e.g. outcome of arithmetic instructions, outcome of instructions that change the control flow of a program)
Instr Pointer
EIP BL
Index Registers
IP
Stack Pointer
FLAG ESP
SP
Base
EBX
BH BX
Flags
EFLAG
Base Pointer
EBP
BP
Count
ECX
CH CX
CL
Segment Registers
CS
Dest Index
EDI
DI
Data
EDX
DH DX
DL DS ES SS FS GS
Source Index
ESI
SI
Base (BH,BL,BX,EBX)
Points to memory locations
Count (CL,CH,CX,ECX)
Counter used typically for loops Can be automatically incremented/decremented
Data (DL,DH,DX,EDX)
Data used in calculations Most significant bits of a 32-bit mul/div operation
Index Registers
SP, ESP
Stack pointer (more on that in upcoming lectures)
BP, EBP
Address stack memory, used to access subroutine arguments
Segment Registers
CS
Points to the memory area where your programs instructions are stored
DS
Points to the memory area where your programs data is stored
SS
Points to the memory area where your stack is stored
ES,FS,GS
They can be used to point to additional data segments, if necessary
Special Registers
IP, EIP
Instruction pointer, points always to the next instruction that the processor is going to execute
FLAG, EFLAG
Flags register, contains individual bits set by different operations (e.g. carry, overflow, zero) Used massively with branch instructions
Memory
You can always view memory as a huge array of bytes Real memory organization is different for efficiency
Odd Bank F D B 9 7 5 3 1 Even Bank
90 E9 F1 01 76 14 55 AB
87 11 24 46 DE 33 12 FF
E C A 8 6 4 2 0
Example: 2222:3333 Linear address: 25553 Example: 2000:5553 Linear address: 25553
Peripherals
For the purposes of this class, peripherals are devices INSIDE the PC box
USB, serial ports Timers Programmable Interrupt Controllers Network cards Other helper devices
Peripherals
Peripherals communicate with the CPU via control, address and data buses, just like memory I/O address bus is 16-bit wide, therefore we are able to address up to 65,535 I/O ports I/O data bus is also 16-bit wide Peripherals can be I/O mapped or memory-mapped or both
Example
My network card I/O Address range 7400743F Memory mapping range C0200000-C0200FFF Both memory-mapped and I/O-mapped We can access this device using different types of instructions
Why not always use assembly language? Assembly language is necessary for writing systems software
Compilers Operating systems (your instructors favorite field)
Assembly language is necessary while designing and evaluating new microprocessors Assembly language is used to program embedded devices and DSPs
Assembly files
Four simple things Labels
Variables are declared as labels pointing to specific memory locations Labels mark the start of subroutines or locations to jump to in your code
Labels
; Labels can be global MyGlobalLabel: MyOtherGlobalLabel: ; They can be local too .MyLocalLabel ; Local labels are always related to the previous un-dotted label
Local labels
MyBigGlobalLabel .local_label1 .local_label2 MyNextBigGlobalLabel .local_label1 ; these are distinct .local_label2 ; to the ones above
Variables
; Lets VAR1 VAR2 VAR3 ARR1 ARR2 STR1 BUF1
labels
do something with labels now DB 255 DB 0FFh DW 1234h DB 12, 34, 56, 78, 90 DW 12, 34, 56, 78, 90 DB 291 is awesome!!!, 0 RESB 80
data
Directives (pseudoinstructions)
Directives
EXTERN: allows you declare external procedures and use them in your program SEGMENT: declare a memory segment EQU: define pre-processor constants
Example
; Let s declare some external functions EXTERN kbdine, dspout, dspmsg, dosxit ; Let s begin our code segment SEGMENT code ; I d normally put my variables right here ..start ; ; ; ; ; This is a special label that denotes the execution starting point. The next instruction after ..start will be the first to run when you execute your program
; ; ; ;
A0 00 00 BB 02 00 43 8A 07