You are on page 1of 7

Lecture 5: Computer

Computer Organization
Architecture
CPU
• Computer Architecture
– Registers Control Unit
– Flags
– Address Calculation ALU

Registers

Output
Input

Memory

8086 Block Diagram


Components Clock
Control Unit
Control Bus

Interrupt
Flags R
• Control Unit –
IP
ALU
• Arithmetic logical unit (ALU) – AX AH AL Instruction
Address
Bus
BX BH BL
Bus
CX CH CL
Data Interface
DX DH DL
• Registers – Unit
Data Registers
Data
Index Registers
Bus
+5V
SI CS
• Buses – DI DS
BP SS
SP ES

1
General Purpose
Registers
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 Special Attributes of GP


15 0
Registers
AX AH AL
7 0 7 0 • AX – accumulator
AH AL

AX 0000 0000 0000 0000


• BX – base
• move 0001 1001 1110 0100 to AX
AH AL
• CX – counter
AX 0001 1001 1110 0100

• move 0011 1101 to AH


• DX – data
AH AL

AX

2
Segment Registers Segment Registers, cont.

• Segment registers are used as • CS – code segment


base locations for program
instructions, data, and the stack.
• All references to memory • DS – data segment
involve a segment register as
the base location.
• SS – stack segment

• ES – extra segment

Index Registers, cont.


Index Registers • BP – base pointer

• Index registers contain the • SP – stack pointer


offsets of data and instructions.
• Offset:
• SI – source index

• Index registers are used when • DI - destination index


processing strings, arrays, and
other data structures.

3
Status and Control
Status Flags
Registers
• IP – instruction pointer • Carry flag (CF)

• Overflow flag (OF)

• Flags –

• Sign flag (SF)

Status Flags, cont. Addressing

• Zero flag (ZF) • Address: a number referring to


an 8-bit memory location
• Logical addresses go from 0 to
the highest location
• Logical addresses require
• Parity translation into physical
addresses
• For Intel (8086):

4
Pins on the 8086
Addressing, cont.
GND 1 40 VCC

D14/A14 2 39 A15/D15

D13/A13 3 38 A16/S3 • How do you have a 20-bit


D12/A12 4 37 A17/S4

D11/A11 5 36 A18/S5 address with 16 bit registers?


D10/A10 6 35 A19/S6
D9/A9 7 34
D8/A8 MN/MX
8 33
D7/A7 9
8086 32 RD

D6/A6 10 RQ/GT0
CPU 31
D5/A5 11 30 R/GT1

D4/A4 12 29 LOCK

D3/A3 13 28 S2
D2/A2 14 27 S1

D1/A1 15 26 S0

D0/A0 16 25 QS0
NMI 17 24 INTA

INTR 18 23 TEST

CLK 19 22 READY
GND 20 21 RESET

Why Segment-Offset? Data Segment


addressable memory on 8086
00000
Example:
DS = 0100h
data seg. start?
data seg. end?

If BX contains the
offset:

BX = 005Ah
EA = ?

FFFFF

5
Segment Register More on Effective
Combinations Addresses
• Code Segment – the CS register • There’s more than one way to
and IP (instruction pointer) are get the same effective address!
used to point to the next • Example:
instruction. – CS = 147Bh
• Stack – the SS register is used – IP = 131Ah
with the SP (stack pointer) or – EA = 147B0 + 131A = 15ACAh
BP (base pointer)
• Data Segment – DS with BX, or
SI, or DI – CS = 15ACh
• Extended Segment – BX, SI, or – IP = 000Ah
DI – EA = 15AC0 + 000A = 15ACAh

Homework 2
• Two parts:
– Part 1: Use Debug to enter and
• If CS = 147B, what range of run a simple machine code
program
effective addresses can be
• convert input data into 2’s
referenced without changing the complement hex
value in CS? • 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.

6
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
Part 1
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 line
• Convert input data into 2’s
below represent the offset of the instruction from the beginning complement hex
of the code segment. The digits after the dash are the machine – use the techniques you used on HW2
code instructions. To the right are English explanations of the
instructions. • Enter data at the correct address
– DS holds the segment
0000 - 2BC0 subtract AX from itself (to make it 0)
0002 - 0307 add the word pointed to by BX to AX – Look at how you did this in lab!
0004 - 83C302
add 2 to BX (to point to the next word)
0007 - 3BD3 compare BX to DX • Enter program at the correct address
(compare sets internal flags that are used by – CS holds the segment
subsequent jump instructions) – IP holds the offset
0009 - 7DF7 if DX >= BX, then jump back to the
instruction at 0002 – Again – look at the lab!
000B - B8004C this instruction and the next one return
control to DOS
• Run your program!
000E - CD21

You might also like