Professional Documents
Culture Documents
Computer Organization
Architecture
CPU
• Computer Architecture
– Registers Control Unit
– Flags
– Address Calculation ALU
Registers
Output
Input
Memory
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!
AX
2
Segment Registers Segment Registers, cont.
• ES – extra segment
3
Status and Control
Status Flags
Registers
• IP – instruction pointer • Carry flag (CF)
• Flags –
4
Pins on the 8086
Addressing, cont.
GND 1 40 VCC
D14/A14 2 39 A15/D15
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
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