ece291 lecture 1 all about computers. ece 291 lecture 1slide 2 of 45 lecture outline errata from...
TRANSCRIPT
ECE291ECE291
Lecture 1Lecture 1
All about computersAll about computers
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 22 of 45 of 45
Lecture outlineLecture outline
Errata from yesterdayErrata from yesterdayClass and Lab SchedulesClass and Lab SchedulesTop-down view of computersTop-down view of computersProcessor architectureProcessor architectureRegistersRegistersMemoryMemoryPeripheralsPeripheralsAssembly primerAssembly primer
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 33 of 45 of 45
HW0 AnswersHW0 Answers
First Transistor: 1948First Transistor: 1948
First Intel Microprocessor: 1985First Intel Microprocessor: 1985
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 44 of 45 of 45
Clarification on Sign ContractionClarification on Sign Contraction
Yesterday I said,Yesterday I said, ““A number can be sign contracted if the bits that are to removed A number can be sign contracted if the bits that are to removed
are all the same”are all the same”
I should have said,I should have said, ““A number can be sign contracted if the bits that are to removed A number can be sign contracted if the bits that are to removed
and the sign bit of the resultant numberand the sign bit of the resultant number are all the same”are all the same”
Example:Example: 0001h = 1 0001h = 1 01h = 1 01h = 1 OKOK FF80h = -128 FF80h = -128 80h = -128 80h = -128 OKOK FF40h = -192 FF40h = -192 40h = 64 40h = 64 NONO 0080h = 128 0080h = 128 80h = -128 80h = -128 NONO
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 55 of 45 of 45
Class and Lab SchedulesClass and Lab Schedules
http://courses.ece.uiuc.edu/ece291/schedule.htmlhttp://courses.ece.uiuc.edu/ece291/schedule.html and and http://courses.ece.uiuc.edu/ece291/labsched.htmlhttp://courses.ece.uiuc.edu/ece291/labsched.html
This is what we decided onThis is what we decided on Any comments, suggestions for improvement, or sarcastic Any comments, suggestions for improvement, or sarcastic
retorts?retorts?
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 66 of 45 of 45
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
Slide Slide 77 of 45 of 45
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
Slide Slide 88 of 45 of 45
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
Slide Slide 99 of 45 of 45
Motherboard
Computers from 10 feetComputers from 10 feet
CPU
Memory
ExpansionBus
Peripherals
Control
Data
Address
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 1010 of 45 of 45
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
Slide Slide 1111 of 45 of 45
Computers from 1 micronComputers from 1 micronCentral Processing Unit – The Processor
ControlBIUALU
Controlregisters
Generalpurposeregisters
Special(floating-point,
flag, sse)
Control
Data
Address
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 1212 of 45 of 45
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
Slide Slide 1313 of 45 of 45
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
Slide Slide 1414 of 45 of 45
The registersThe registers
Small memory locations that are quickly Small memory locations that are quickly accessible by the processoraccessible by the processor
Located on the chipLocated on the chip
Hold data and results for operationsHold data and results for operations
Point to main memory locationsPoint to main memory locations
Contain status information about the Contain status information about the results of operationsresults of operations
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 1515 of 45 of 45
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
Inst 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
Slide Slide 1616 of 45 of 45
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
Slide Slide 1717 of 45 of 45
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 Used in multiplication/division instructions Used in multiplication/division instructions
along with accumulatoralong with accumulator
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 1818 of 45 of 45
Register specificsRegister specifics
Source index (SI, ESI)Source index (SI, ESI) Often used to address a source variable or Often used to address a source variable or
arrayarray
Destination index (DI, EDI)Destination index (DI, EDI) Often used to address a destination variable Often used to address a destination variable
or arrayor array
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 1919 of 45 of 45
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 It’s better to mess with this one, though you It’s better to mess with this one, though you
can still get you in troublecan still get you in trouble Can be used to read subroutine argumentsCan be used to read subroutine arguments
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 2020 of 45 of 45
Register SpecificsRegister Specifics
Get in the habit of using these registers for Get in the habit of using these registers for their intended tasks as much as possibletheir intended tasks as much as possible
It will greatly help you (and us) in reading It will greatly help you (and us) in reading and debugging your code!and debugging your code!
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 2121 of 45 of 45
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
Slide Slide 2222 of 45 of 45
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
Slide Slide 2323 of 45 of 45
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
Slide Slide 2424 of 45 of 45
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
Slide Slide 2525 of 45 of 45
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
Slide Slide 2626 of 45 of 45
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
Slide Slide 2727 of 45 of 45
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
Slide Slide 2828 of 45 of 45
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 motherboard, or in expansion slotson the motherboard, or in expansion slots
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 2929 of 45 of 45
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
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
Example:Example: In real mode, The keyboard input (scan code) is read In real mode, The keyboard input (scan code) is read
in on port 60h. Each scan code is one byte.in on port 60h. Each scan code is one byte.
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 3030 of 45 of 45
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
Slide Slide 3131 of 45 of 45
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
Slide Slide 3232 of 45 of 45
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
Slide Slide 3333 of 45 of 45
IntermissionIntermission
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 3434 of 45 of 45
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
Slide Slide 3535 of 45 of 45
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
ECE 291 Lecture 1ECE 291 Lecture 1
Slide Slide 3636 of 45 of 45
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
Slide Slide 3737 of 45 of 45
Assembly primer - commentsAssembly primer - comments
; Comments are denoted by semi-colons.; Comments are denoted by semi-colons.
; These are comments; These are comments
; Please comment your MP’s!; Please comment your MP’s!
; 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
Slide Slide 3838 of 45 of 45
Assembly primer - labelsAssembly primer - labels
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?”You may also not care at allYou may also not care at allVariables are nothing more than labels Variables are nothing more than labels that mark specific memory locationsthat mark specific memory locationsLabels 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
Slide Slide 3939 of 45 of 45
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
Slide Slide 4040 of 45 of 45
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
Slide Slide 4141 of 45 of 45
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
Slide Slide 4242 of 45 of 45
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
Slide Slide 4343 of 45 of 45
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
; Normally variables would go here; Normally variables would go here
..start..start ; This is a special label that; This is a special label that; denotes the execution starting; denotes the execution starting; point in NASM. The next instruction; point in NASM. 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
Slide Slide 4444 of 45 of 45
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
Slide Slide 4545 of 45 of 45
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
Slide Slide 4646 of 45 of 45
AssignmentsAssignments
Keep working on MP0 and HW0Keep working on MP0 and HW0