ECE 361 Computer Architecture Lecture 4: MIPS Instruction Set Architecture
Lecture 5: Computer Architecture
Click here to load reader
-
Upload
simranjotsingh -
Category
Documents
-
view
110 -
download
4
description
Transcript of Lecture 5: Computer Architecture
1
Lecture 5: Computer Architecture
• Computer Architecture– Registers– Flags– Address Calculation
Computer Organization
Control Unit
ALU
Registers
Memory
CPU
Input Output
Components
• Control Unit –
• Arithmetic logical unit (ALU) –
• Registers –
• Buses –
8086 Block Diagram
CSDSSSES
SIDIBPSP
AXBXCXDX
AHBHCHDH
ALBLCLDL
Data Registers
Index Registers
ALU
Bus Interface
Unit
IP
Flags R
Control Unit
Instruction
Data
DataBus
AddressBus
Control BusClock
Interrupt
+5V
2
RegistersGeneral Purpose
Registers
• Data registers, also known as general purpose registers: AX, BX, CX, DX
• Used for arithmetic operations and data movement
• Can be addressed as 16 bit or 8 bit values. For AX, upper 8 bits are AH, lower 8 bits are AL.
• Remember: when when a 16 bit register is modified, so are the corresponding 8 bit registers!
Example
• move 0001 1001 1110 0100 to AX
AX AH AL
15 0
7 0 7 0
AX
AH AL
0000 0000 0000 0000
AX
AH AL
0001 1001 1110 0100
• move 0011 1101 to AH
AX
AH AL
Special Attributes of GP Registers
• AX – accumulator
• BX – base
• CX – counter
• DX – data
3
Segment Registers
• Segment registers are used as base locations for program instructions, data, and the stack.
• All references to memory involve a segment register as the base location.
Segment Registers, cont.
• CS – code segment
• DS – data segment
• SS – stack segment
• ES – extra segment
Index Registers
• Index registers contain the offsets of data and instructions.
• Offset:
• Index registers are used when processing strings, arrays, and other data structures.
Index Registers, cont.• BP – base pointer
• SP – stack pointer
• SI – source index
• DI - destination index
4
Status and Control Registers
• IP – instruction pointer
• Flags –
Status Flags
• Carry flag (CF)
• Overflow flag (OF)
• Sign flag (SF)
Status Flags, cont.
• Zero flag (ZF)
• Parity
Addressing
• Address: a number referring to an 8-bit memory location
• Logical addresses go from 0 to the highest location
• Logical addresses require translation into physical addresses
• For Intel (8086):
5
Pins on the 8086
1
2
3
4
5
6
7
8
9
10
11
12
14
13
15
16
17
18
19
20
40
39
38
37
36
35
34
33
32
31
30
29
27
28
26
25
24
23
22
21
8086CPU
GND
D14/A14
D13/A13
D12/A12
D11/A11
D10/A10
D9/A9
D8/A8
D7/A7
D6/A6
D5/A5
D4/A4
D3/A3
D2/A2
D1/A1
D0/A0
NMI
INTR
CLK
GND
VCC
A15/D15
A16/S3
A17/S4
A18/S5
A19/S6
MN/MX
RD
RQ/GT0
R/GT1
LOCK
S2
S1
S0
QS0
INTA
TEST
READY
RESET
Addressing, cont.
• How do you have a 20-bit address with 16 bit registers?
Why Segment-Offset? Data Segmentaddressable memory on 8086
FFFFF
00000Example:DS = 0100h
data seg. start?data seg. end?
If BX contains theoffset:
BX = 005AhEA = ?
6
Segment Register Combinations
• Code Segment – the CS register and IP (instruction pointer) are used to point to the next instruction.
• Stack – the SS register is used with the SP (stack pointer) or BP (base pointer)
• Data Segment – DS with BX, SI, or DI
• Extended Segment – BX, SI, or DI
More on Effective Addresses
• There’s more than one way to get the same effective address!
• Example:– CS = 147Bh– IP = 131Ah– EA = 147B0 + 131A = 15ACAh
or– CS = 15ACh– IP = 000Ah– EA = 15AC0 + 000A = 15ACAh
• If CS = 147B, what range of effective addresses can be referenced without changing the value in CS?
Homework 2• Two parts:
– Part 1: Use Debug to enter and run a simple machine code program
• convert input data into 2’s complement hex
• enter data at the correct address• enter program at the correct address• run the program
– Part 2: Write a simple machine code program, given pseudo-code
• these instructions should be similar to those in the Part 1 problem.
• enter and run the resulting program.
7
Part I - Example Program Given below is a machine code program that calculates the sum of all the words in a given range of addresses in memory. The code expects that the lower bound of this range is specified in the BX register and the upper bound in the DX register. (BX holds the offset of the beginning of the data to be summed from the beginning of the data segment (DS). DX holds the offset of the last data element from the beginning of the data segment.) The sum gets stored in AX. The first 4 hex digits given on each linebelow represent the offset of the instruction from the beginningof the code segment. The digits after the dash are the machine code instructions. To the right are English explanations of the instructions.
0000 - 2BC0 subtract AX from itself (to make it 0) 0002 - 0307 add the word pointed to by BX to AX 0004 - 83C302 add 2 to BX (to point to the next word) 0007 - 3BD3 compare BX to DX
(compare sets internal flags that are used by subsequent jump instructions)
0009 - 7DF7 if DX >= BX, then jump back to the instruction at 0002
000B - B8004C this instruction and the next one return control to DOS
000E - CD21
Part 1
• Convert input data into 2’s complement hex– use the techniques you used on HW2
• Enter data at the correct address– DS holds the segment– Look at how you did this in lab!
• Enter program at the correct address– CS holds the segment– IP holds the offset– Again – look at the lab!
• Run your program!