ece291
DESCRIPTION
ECE291. Lecture 1 All about computers. Lecture outline. Top-down view of computers Processor architecture Registers Memory Peripherals Assembly primer Assignments. Computers from 50,000 feet. Basic components Mouse Keyboard Monitor Printer Scanner Joystick “The box”. Power. - PowerPoint PPT PresentationTRANSCRIPT
ECE291ECE291
Lecture 1Lecture 1
All about computersAll about computers
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 22 of 41 of 41
Lecture outlineLecture outline
Top-down view of computersTop-down view of computers
Processor architectureProcessor architecture
RegistersRegisters
MemoryMemory
PeripheralsPeripherals
Assembly primerAssembly primer
AssignmentsAssignments
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 33 of 41 of 41
Computers from 50,000 feetComputers from 50,000 feet
Basic componentsBasic components MouseMouse KeyboardKeyboard MonitorMonitor PrinterPrinter ScannerScanner JoystickJoystick ““The box”The box”
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 44 of 41 of 41
Computers from 10,000 feetComputers from 10,000 feet
Sound cardSerialSCSI
Parallel
Keyboard/Mouse USB ExpansionVGA
Network
Power
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 55 of 41 of 41
Computers from 100 feetComputers from 100 feet
Cooling fan
Pow
er s
uppl
y
Mem
ory P
rocessor
Expansion bus
Motherboard
IDE and SCSI cables and devices
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 66 of 41 of 41
Motherboard
Computers from 10 feetComputers from 10 feet
CPU
Memory
ExpansionBus
Peripherals
Control
Data
Address
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 77 of 41 of 41
Motherboard
Computers from 10 feetComputers from 10 feet
Processor
8088
8086
80286
80386dx
80486
80586/Pentium (Pro)
Data Bus
8
16
16
32
32
64
Address Bus
20
20
24
32
32
32
Max Addressable Memory
1,048,576 (1Mb)
1,048,576 (1Mb)
16,777,21 (16Mb)
4,294,976,296 (4Gb)
4,294,976,296 (4Gb)
4,294,976,296 (4Gb)
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 88 of 41 of 41
Computers from 1 micronComputers from 1 micronCentral Processing Unit – The Processor
ALUBIU
Control
Controlregisters
Generalpurposeregisters
Special(floating-point,
flag, sse)
Control
Data
Address
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 99 of 41 of 41
The processorThe processor
It’s a state machineIt’s a state machine
Has a set of hard-coded operationsHas a set of hard-coded operations Each operation has an associated code;Each operation has an associated code;
an “opcode”an “opcode” Some examples are MOV, ADD, SUB, ANDSome examples are MOV, ADD, SUB, AND
All it can do is move data or perform some All it can do is move data or perform some calculation on datacalculation on data
Very simple, right?Very simple, right?
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1010 of 41 of 41
The processor - componentsThe processor - components
CPU RegistersCPU Registers Special memory locations constructed from flip-flops and Special memory locations constructed from flip-flops and
implemented on-chipimplemented on-chip E.g., accumulator, count register, flag registerE.g., accumulator, count register, flag register
Arithmetic and logic Unit (ALU)Arithmetic and logic Unit (ALU) Where most of the action takes place inside the CPUWhere most of the action takes place inside the CPU
Bus Interface Unit (BIU)Bus Interface Unit (BIU) Responsible for controlling the address and data busses when Responsible for controlling the address and data busses when
accessing main memory and data in the cacheaccessing main memory and data in the cache
Control Unit and Instruction SetControl Unit and Instruction Set CPU has a fixed set of instructionsCPU has a fixed set of instructions E.g. MOV, CMP, ADD, JMPE.g. MOV, CMP, ADD, JMP
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1111 of 41 of 41
The registersThe registers
Small memory locations that are quickly Small memory locations that are quickly accessible by the processoraccessible by the processor
Hold data and results for operationsHold data and results for operations
Point to memory locationsPoint to memory locations
Contain status information about the Contain status information about the results of operationsresults of operations
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1212 of 41 of 41
80x86 registers80x86 registers
Accumulator
EAX
AH AL
AX
Base
EBX
BH BL
BX
Count
ECX
CH CL
CX
Data
EDX
DH DL
DX
General Purpose
Instr Pointer
EIP
IP
Flags
EFLAG
FLAG
Special Registers
Stack Segment
Code SegmentCS
Data SegmentDS
Extra SegmentES
SS
FS
GS
Segment Registers
Stack Pointer
ESP
SP
Base Pointer
EBP
BP
Dest Index
EDI
DI
Source Index
ESI
SI
Index Registers
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1313 of 41 of 41
Register specificsRegister specifics
Accumulator (AL, AH, AX, EAX)Accumulator (AL, AH, AX, EAX) Usually stores results from the ALUUsually stores results from the ALU It “accumulates” totals from math operationsIt “accumulates” totals from math operations General purposeGeneral purpose
Base (BL, BH, BX, EBX)Base (BL, BH, BX, EBX) Usually holds addresses – points to memory Usually holds addresses – points to memory
locationslocations
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1414 of 41 of 41
Register specificsRegister specifics
Count (CL, CH, CX, ECX)Count (CL, CH, CX, ECX) Counting and loopingCounting and looping Certain instructions automatically decrement Certain instructions automatically decrement
the count registerthe count register
Data (DL, DH, DX, EDX)Data (DL, DH, DX, EDX) Usually contains data for instructionsUsually contains data for instructions Contain the most significant bytes of 16-bit Contain the most significant bytes of 16-bit
Mul/div’sMul/div’s
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1515 of 41 of 41
Register specificsRegister specifics
Stack pointer (SP, ESP)Stack pointer (SP, ESP) Used by stack operationsUsed by stack operations Usually you don’t want to mess with this oneUsually you don’t want to mess with this one
Base pointer (BP, EBP)Base pointer (BP, EBP) Addresses stack memoryAddresses stack memory Can be used to read subroutine argumentsCan be used to read subroutine arguments
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1616 of 41 of 41
Register specificsRegister specifics
Source index (SI, ESI)Source index (SI, ESI) Often used to address a source array or string Often used to address a source array or string
data typedata type
Destination index (DI, EDI)Destination index (DI, EDI) Often used to address a destination array or Often used to address a destination array or
string data typestring data type
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1717 of 41 of 41
Register specificsRegister specifics
Code segment (CS)Code segment (CS) Points to the area in memory where Points to the area in memory where
instructions are storedinstructions are stored
Instruction pointer (IP)Instruction pointer (IP) An index into the code segment that points to An index into the code segment that points to
the next instruction to be executedthe next instruction to be executed
Data segment (DS)Data segment (DS) Points to the area in memory where data Points to the area in memory where data
needed by a program is storedneeded by a program is stored
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1818 of 41 of 41
Register specificsRegister specifics
Stack segment (SS)Stack segment (SS) Points to the area in memory containing the Points to the area in memory containing the
system’s FIFO stack. We’ll have a whole system’s FIFO stack. We’ll have a whole lecture on this.lecture on this.
ES, FS, GSES, FS, GS Extra segment registers available to point to Extra segment registers available to point to
additional data segments should that be additional data segments should that be necessary.necessary.
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 1919 of 41 of 41
MemoryMemory
System memory or RAM holds data and System memory or RAM holds data and instruction opcodes that are being used by instruction opcodes that are being used by the CPUthe CPU
Organized in banks, usually even and oddOrganized in banks, usually even and odd
Always byte addressableAlways byte addressable
More on all this tomorrowMore on all this tomorrow
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2020 of 41 of 41
Memory access exampleMemory access example
CPU wants to read memory at address 12345h
CPU MemoryRead Signal
Data
12345h
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2121 of 41 of 41
Memory organizationMemory organization
AB1 FF55 1214 3376 DE01 46F1 24E9 1190 87
3
5
7
9
B
D
F
0
2
4
6
8
A
C
E
Odd Bank Even Bank
Data Bus (15:8) Data Bus (7:0)
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2222 of 41 of 41
Memory organizationMemory organization
In Real Mode:In Real Mode: The address bus is 20-bits for memory The address bus is 20-bits for memory
operations.operations. 222020 = 1MB = how much memory an x86 = 1MB = how much memory an x86
processor can address in real modeprocessor can address in real mode The data bus is 16-bits which means it can The data bus is 16-bits which means it can
transfer two bytes in one operationtransfer two bytes in one operation Limited to 16-bit registersLimited to 16-bit registers
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2323 of 41 of 41
Memory organizationMemory organization
In Protected Mode:In Protected Mode: The memory address bus is 32-bitsThe memory address bus is 32-bits 223232 = 4GB = the maximum addressable = 4GB = the maximum addressable
amount of memory in modern x86 processorsamount of memory in modern x86 processors Data bus is also 32-bits meaning four bytes Data bus is also 32-bits meaning four bytes
can be transferred in a single operationcan be transferred in a single operation Gain access to the 32-bit extended registersGain access to the 32-bit extended registers
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2424 of 41 of 41
PeripheralsPeripherals
In our context, things like printers, In our context, things like printers, joysticks, and scanners aren’t peripheralsjoysticks, and scanners aren’t peripherals
Some examples are parallel, serial and Some examples are parallel, serial and USB ports, the internal timers, interrupt USB ports, the internal timers, interrupt controllers, network interface cardscontrollers, network interface cards
Many helper devices inside the processor, Many helper devices inside the processor, on the mother board, or in expansion slotson the mother board, or in expansion slots
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2525 of 41 of 41
Peripheral I/O busPeripheral I/O bus
There is a separate set of address/data busses There is a separate set of address/data busses commonly used for communication with commonly used for communication with peripheral devicesperipheral devices
In reality, they’re the same busses, just different In reality, they’re the same busses, just different signals in the control bus cause different things signals in the control bus cause different things to happento happen
The I/O address bus is 16-bits wide, meaning The I/O address bus is 16-bits wide, meaning you can address 65,535 different I/O ports.you can address 65,535 different I/O ports.
The I/O data bus is 16-bitsThe I/O data bus is 16-bits
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2626 of 41 of 41
Peripheral I/OPeripheral I/O
Peripheral devices don’t Peripheral devices don’t havehave to use the to use the I/O bus. They can be memory mapped.I/O bus. They can be memory mapped.
Video cards are an exampleVideo cards are an example
They have a large amount of memory They have a large amount of memory (VRAM) and that is typically mapped to a (VRAM) and that is typically mapped to a range of addresses in the memory spacerange of addresses in the memory space
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2727 of 41 of 41
Peripheral examplePeripheral example
Network cardNetwork card
Input/Output Range Input/Output Range CC00-CC7FCC00-CC7F
Memory Range Memory Range FB000000-FB00007FFB000000-FB00007F
This one is both This one is both memory mapped memory mapped andand I/O mappedI/O mapped
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2828 of 41 of 41
PeripheralsPeripherals
All this really means to you is that All this really means to you is that sometimes you’ll use one set of sometimes you’ll use one set of instructions to access a device, and instructions to access a device, and sometimes you’ll use a different set.sometimes you’ll use a different set.
We’ll talk about this again when we cover We’ll talk about this again when we cover serial/parallel ports, timers, interrupts, and serial/parallel ports, timers, interrupts, and the video graphics adapter.the video graphics adapter.
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 2929 of 41 of 41
Instruction processingInstruction processing
Processing of an instruction by the Processing of an instruction by the microprocessor consists of three basic steps microprocessor consists of three basic steps
1.1. fetch instruction from the memoryfetch instruction from the memory2.2. decode the instructiondecode the instruction3.3. execute (usually involves accessing the memory for execute (usually involves accessing the memory for
getting operands and storing results)getting operands and storing results)
Operation of an early processor like the Intel Operation of an early processor like the Intel 80858085
Fetch1
Decode1
Execute1
Fetch2
Decode2
Execute2
…...
Busy Idle Busy …...Busy Idle Busy
Microprocessor
Bus
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3030 of 41 of 41
Instruction processingInstruction processing
Fetch1
Fetch2
Fetch5
Fetch3
Fetch4
Modern microprocessors can process several instructions Modern microprocessors can process several instructions simultaneously at various stages of executionsimultaneously at various stages of execution
this ability is called pipeliningthis ability is called pipelining
Operation of a pipelined microprocessor like the Intel 80486Operation of a pipelined microprocessor like the Intel 80486
Store1
Fetch6
Fetch7
Read2
Decode1
Decode2
Decode3
Decode4
Decode5
Decode6Idle Idle
Execute1 Idle
Execute2
Execute3
Execute4
Execute5
Execute6
GenerateAddress
1
GenerateAddress
2
Bus Unit
Instruction Unit
Execution Unit
Address Unit
Modern microprocessors can process several instructions Modern microprocessors can process several instructions simultaneously at various stages of executionsimultaneously at various stages of execution
this ability is called pipeliningthis ability is called pipelining
Operation of a pipelined microprocessor like the Intel 80486Operation of a pipelined microprocessor like the Intel 80486
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3131 of 41 of 41
Assembly primerAssembly primer
Everything in your assembly file is one of Everything in your assembly file is one of the following:the following: A commentA comment A labelA label An instruction or directiveAn instruction or directive DataData
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3232 of 41 of 41
Assembly primer - commentsAssembly primer - comments
; Comments are denoted by semi-colons.; Comments are denoted by semi-colons.
; These are comments!!! Yeah!!!.; These are comments!!! Yeah!!!.
; Please comment your MP’s thoroughly.; Please comment your MP’s thoroughly.
; It helps us figure out what you were doing; It helps us figure out what you were doing
; It also helps you figure out what you were; It also helps you figure out what you were
; doing when you look back at code you; doing when you look back at code you
; wrote more than two minutes ago.; wrote more than two minutes ago.
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3333 of 41 of 41
Assembly primerAssembly primer
You might be asking, “What about You might be asking, “What about variables? Why aren’t they on the bulleted variables? Why aren’t they on the bulleted list?”list?”
Variables are nothing more than labels Variables are nothing more than labels that mark specific memory locationsthat mark specific memory locations
Labels can also mark the beginning of Labels can also mark the beginning of procedures or “jump to” locations in your procedures or “jump to” locations in your codecode
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3434 of 41 of 41
Assembly primer - labelsAssembly primer - labels
; Labels can be global; Labels can be global
MyGlobalLabel:MyGlobalLabel:
MyOtherGlobalLabelMyOtherGlobalLabel
; They can be local too; They can be local too
.MyLocalLabel.MyLocalLabel
; Local labels are good only back to the ; Local labels are good only back to the previous un-dotted labelprevious un-dotted label
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3535 of 41 of 41
Assembly primer - labelsAssembly primer - labels
MyBigGlobalLabelMyBigGlobalLabel
.local_label1.local_label1
.local_label2.local_label2
MyNextBigGlobalLabelMyNextBigGlobalLabel
.local_label1.local_label1 ; these are distinct; these are distinct
.local_label2.local_label2 ; to the ones above; to the ones above
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3636 of 41 of 41
Assembly primer - variablesAssembly primer - variables
; Let’s do something with labels now; Let’s do something with labels now
VAR1 DB 255VAR1 DB 255
VAR2 DB 0FFhVAR2 DB 0FFh
VAR3 DW 1234hVAR3 DW 1234h
ARR1 DB 12, 34, 56, 78, 90ARR1 DB 12, 34, 56, 78, 90
ARR2 DW 12, 34, 56, 78, 90ARR2 DW 12, 34, 56, 78, 90
STR1 DB ‘291 is awesome!!!’, 0STR1 DB ‘291 is awesome!!!’, 0
BUF1 RESB 80BUF1 RESB 80
labels directives data
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3737 of 41 of 41
Assembly primer - directivesAssembly primer - directives
EXTERN – allows you to declare external EXTERN – allows you to declare external procedures so you can use them in your procedures so you can use them in your program.program.SEGMENT – lets you declare the SEGMENT – lets you declare the beginning of a memory segment. We’ll beginning of a memory segment. We’ll talk in detail about memory segments talk in detail about memory segments tomorrow.tomorrow.EQU – lets you define pre-processor EQU – lets you define pre-processor constants.constants.
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3838 of 41 of 41
Assembly primer - directivesAssembly primer - directives
; Let’s declare some external functions; Let’s declare some external functionsEXTERN kbdine, dspout, dspmsg, dosxitEXTERN kbdine, dspout, dspmsg, dosxit
; Let’s begin our code segment; Let’s begin our code segmentSEGMENT codeSEGMENT code
; I’d normally put my variables right here; I’d normally put my variables right here
..start..start ; This is a special label that; This is a special label that; denotes the execution starting; denotes the execution starting; point. The next instruction; point. The next instruction; after ..start will be the first; after ..start will be the first; to run when you execute your program; to run when you execute your program
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 3939 of 41 of 41
Assembly primer - instructionsAssembly primer - instructions
; Here are some simple instructions; Here are some simple instructions
mov ax, [VAR1] ; notice the bracketsmov ax, [VAR1] ; notice the brackets
mov dx, STR1 ; notice the not bracketsmov dx, STR1 ; notice the not brackets
call dspmsgcall dspmsg
jmp donejmp done
mov bx, [VAR2] ; this will never happenmov bx, [VAR2] ; this will never happen
donedone
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 4040 of 41 of 41
ExampleExample
SEGMENT codeSEGMENT codevar1var1 dbdb 55h55h ; 55; 55var2var2 dbdb 0AAh0AAh ; AA; AAvar3var3 dbdb 12h12h ; 12; 12str1str1 dbdb "Hello", 0"Hello", 0 ; 48 65 6C 6C 6F 00; 48 65 6C 6C 6F 00
..start..startmovmov al,al, [var1][var1] ; A0 00 00; A0 00 00movmov bx,bx, var3var3 ; BB 02 00; BB 02 00incinc bxbx ; 43; 43movmov al,al, [bx][bx] ; 8A 07; 8A 07
ECE 291 Lecture 1ECE 291 Lecture 1
Page Page 4141 of 41 of 41
AssignmentsAssignments
Keep working on MP0 and HW0Keep working on MP0 and HW0