Professional Documents
Culture Documents
Second Term
2019- 2020
CHAPTER 6:
Objectives
• Machine instructions and program execution, including
branching and subroutine call and return operations.
• Number representation and addition/subtraction in the 2’s-
complement system.
• Addressing methods for accessing register and memory
operands.
• Assembly language for representing machine instructions,
data, and programs.
• Program-controlled Input/Output operations.
Computer Architecture
Signed Integer
• 3 major representations:
Sign and magnitude
One’s complement
Two’s complement
• Assumptions:
4-bit machine word
16 different values can be represented
Roughly half are positive, half are negative
Computer Architecture
-7 +0
-6 1111 0000 +1
1110 0001
-5 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
-1 +0
-2 1111 0000 +1
1110 0001
-3 +2 +
like 1's comp 1101 0010
except shifted -4 1100 0011 +3 0 100 = + 4
one position
clockwise -5 1011 0100 +4 1 100 = - 4
1010 0101
-6 +5 -
1001 0110
-7 1000 0111 +6
-8 +7
Sign and
b 3 b 2 b1 b 0 magnitude 1' s complement 2' s complement
0 1 1 1 +7 +7 + 7
0 1 1 0 +6 +6 + 6
0 1 0 1 +5 +5 + 5
0 1 0 0 +4 +4 + 4
0 0 1 1 +3 +3 + 3
0 0 1 0 +2 +2 + 2
0 0 0 1 +1 +1 + 1
0 0 0 0 +0 +0 + 0
1 0 0 0 - 0 -7 - 8
1 0 0 1 - 1 -6 - 7
1 0 1 0 - 2 -5 - 6
1 0 1 1 - 3 -4 - 5
1 1 0 0 - 4 -3 - 4
1 1 0 1 - 5 -2 - 3
1 1 1 0 - 6 - 1 - 2
1 1 1 1 - 7 -0 - 1
•
•
•
last word
Memory words.
Computer Architecture
b31 b30 b1 b0
•
•
•
Sign bit: b31= 0 for positive numbers
b31= 1 for negative numbers
Memory Operation
• Load (or Read or Fetch)
Copy the content. The memory content doesn’t change.
Address – Load
Registers can be used
• Store (or Write)
Overwrite the content in memory
Address and Data – Store
Registers can be used
Computer Architecture
ADDRESSING MODES
Computer Architecture
Addressing Modes
Addressing Modes
• Register Indirect
• Indicate the register that holds the number of the register that holds
the operand
MOV R1, (R2) R1
• Autoincrement / Autodecrement
R2 = 3
• Access & update in 1 instr.
• Direct Address R3 = 5
• Use the given address to access a memory location
Computer Architecture
Addressing Modes
• Indirect Address
• Indicate the memory location that holds the address of the memory
location that holds the data
Memory
AR = 101
100
101 0 1 0 4
102
103
104 1 1 0 A
Computer Architecture
Addressing Modes
Memory
• Relative Address
• EA = PC + Relative Addr 0
1
PC = 2 2
100
AR = 100
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
Computer Architecture
Addressing Modes
• Indexed
Memory
• EA = Index Register + Relative Addr
Useful with XR = 2
“Autoincrement” or
“Autodecrement”
+
100
AR = 100
101
Could be Positive or
Negative 102 1 1 0 A
(2’s Complement) 103
104
Computer Architecture
Addressing Modes
• Base Register
Memory
• EA = Base Register + Relative Addr
Could be Positive or AR = 2
Negative
(2’s Complement)
+
100 0 0 0 5
BR = 100
101 0 0 1 2
102 0 0 0 A
Usually points to 103 0 1 0 7
the beginning of 104 0 0 5 9
an array
Computer Architecture
Addressing Modes
Name Assembler syntax Addressingfunction
• The different
ways in which Immediate #Value Op erand = Value
the location of
an operand is Register Ri EA = Ri
specified in an Absolute (Direct) LOC EA = LOC
instruction are
referred to as Indirect (R i ) EA = [Ri ]
addressing (LOC) EA = [LOC]
modes.
Index X(R i ) EA = [Ri ] + X
Autoincrement (R i )+ EA = [Ri ] ;
Increment R i
Autodecrement (R i ) Decrement R i ;
EA = [Ri ]
Computer Architecture
Relative Addressing
• Relative mode – the effective address is determined
by the Index mode using the program counter in
place of the general-purpose register.
• X(PC) – note that X is a signed number
• Branch>0 LOOP
• This location is computed by specifying it as an offset
from the current value of PC.
• Branch target may be either before or after the
branch instruction, the offset is given as a singed
num.
Computer Architecture
Additional Modes
• Autoincrement mode – the effective address of the operand is the
contents of a register specified in the instruction. After accessing
the operand, the contents of this register are automatically
incremented to point to the next item in a list.
• (Ri)+. The increment is 1 for byte-sized operands, 2 for 16-bit
operands, and 4 for 32-bit operands.
• Autodecrement mode: -(Ri) – decrement first
Move N,R1
Move #NUM1,R2 Initialization
Clear R0
LOOP Add (R2)+,R0
Decrement R1
Branch>0 LOOP
Move R0,SUM
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
Computer Architecture
ASSEMBLY LANGUAGE
Computer Architecture
(iii) 80286
• Runs faster than 8086 and 8088
• Can address up to 16 MB of internal memory
• multitasking => more than 1 task can be ran
simultaneously
(iv) 80386
• has 32-bit registers and 32-bit data bus
• can address up to 4 billion bytes. of memory
• support “virtual mode”, whereby it can swap portions of
memory onto disk: in this way, programs running
concurrently have space to operate.
(v) 80486
• has 32-bit registers and 32-bit data bus
• the presence of CACHE
Computer Architecture
(vi) Pentium
• has 32-bit registers, 64-bit data bus
• has separate caches for data and instruction
• the processor can decode and execute more than
one
• instruction in one clock cycle (pipeline)
EU
• EU is responsible for program execution
• Contains of an Arithmetic Logic Unit (ALU), a Control Unit (CU)
and a number of registers
BIU
• Delivers data and instructions to the EU.
• manage the bus control unit, segment registers and instruction
queue.
• The BIU controls the buses that transfer the data to the EU, to
memory and to external input/output devices, whereas the
segment registers control memory addressing.
Computer Architecture
AX AH AL
BX BH BL
CX CH CL
Program Control
DX DH DL
SP CS
BP DS
SI SS
DI ES
Bus Bus
Control
Unit
ALU 1
CU 2
Flag register 3 Instruction
4 Queue
Instruction Pointer n
(Program Counter)
Computer Architecture
register 05 29
memory
29 05
Segment register
(in CPU)
memory
(MM)
Computer Architecture
Segment Offsets
Eg:
A starting address of data segment is 038E0H, so the
value in DS register is 038E0H. An instruction
references a location with an offset of 0032H bytes
from the start of the data segment.
Registers
• Registers are used to control instructions being
executed, to handle addressing of memory,
and to provide arithmetic capability
• Registers of Intel Processors can be
categorized into:
1. Segment register
2. Pointer register
3. General purpose register
4. Index register
5. Flag register
Computer Architecture
i) Segment register
(a) CS register
• Contains the starting address of program’s code segment.
• The content of the CS register is added with the content in the
Instruction Pointer (IP) register to obtain the address of the
instruction that is to be fetched for execution.
(Note: common name for IP is PC (Program Counter))
(b) DS register
• Contains the starting address of a program’s data segment.
• The address in DS register will be added with the value in the
address field (in instruction format) to obtain the real address
of the data in data segment.
Computer Architecture
(c) SS Register
• Contains the starting address of the stack segment.
• The content in this register will be added with the content in
the Stack Pointer (SP) register to obtain the required word.
(d) ES (Extra Segment) Register
• Used by some string (character data) operations to handle
memory addressing
• ES register is associated with the Data Index (DI) register.
Example :
The content in CS register = 39B40H
The content in IP register = 514H
(a) AX register
• Acts as the accumulator and is used in operations that
involve input/output and arithmetic
• The diagram below shows the AX register with the number of
bits.
32 bits
8 bit 8 bit
AH AL
AX
EAX
EAX : 32 bit
AX : 16 bit (rightmost 16-bit portion of EAX)
AH : 8 bit => leftmost 8 bits of AX (high portion)
AL : 8 bit => rightmost 8 bit of AX (low portion)
Computer Architecture
(b) BX Register
o Known as the base register since it is the only this
general purpose register that can be used as an index to
extend addressing.
o This register also can be used for computations
o BX can also be combined with DI and SI register as a
base registers for special addressing like AX, BX is also
consists of EBX, BH and BL
32 bits
8 bit 8 bit
BH BL
BX
EBX
Computer Architecture
(c) CX Register
• known as count register
• may contain a value to control the number of times a
loops is repeated or a value to shift bits left or right
• CX can also be used for many computations
• Number of bits and fractions of the register is like
below :
32 bits
8 bit 8 bit
CH CL
CX
ECX
Computer Architecture
(d) DX Register
• Known as data register
• Some I/O operations require its use
• Multiply and divide operations that involve large values
assume the use of DX and AX together as a pair to hold
the data or result of operation.
• Number of bits and the fractions of the register is as
below :
32 bits
8 bit 8 bit
DH DL
DX
EDX
Computer Architecture
(a) SI Register
o Needed in operations that involve string (character) and is
always usually associated with the DS register
o SI : 16 bit
o ESI : 32 bit (80286 and above)
(b) DI Register
o Also used in operations that involve string (character) and it is
associated with the ES register
o DI : 16 bit
o EDI : 32 bit (80386 and above)
Computer Architecture
15 14 13 12 11 10 9 8 7 6 5 4 3 2
1 0
O D I T S Z A P C
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Instruction Format
opcode
2 3 4
1
Computer Architecture
opcode address
Instruction-3-address
opcode address for Result address for Operand 1 address for Operand 2
Instruction-2-address
opcode address for Operand 1 & Result address for Operand 2
Instruction-1-address
opcode address for Operand 2
• Example :
LOAD A
ADD B AC = AC + B
or
SUB B AC = AC - B
– Operand 1 & Result in AC (accumulator), a register
– SUB B B subtracts from AC, the result stored in AC
– Address for Next instruction? program counter (PC)
• Short instruction (requires less bit) but need more
instructions for arithmetic problem
Computer Architecture
Y = (A-B) / (C+D x E)
Instruction Comment
• SUB Y, A, B •Y A-B
• MPY T, D, E •T DxE
• ADD T, T, C •T T+C
• DIV Y, Y, T •Y Y/ T
Three-address instructions
Computer Architecture
Y = (A-B) / (C+D x E)
• MOVE Y, A
• SUB Y, B
• MOVE T, D
• MPY T, E
• ADD T, C
• DIV Y, T
Two-address instructions
Computer Architecture
Y = (A-B) / (C+D x E)
INSTRUCTIONS Comment
• LOAD D • AC D
• MPY E
• AC AC x E
• ADD C
• AC AC + C
• STOR Y
• LOAD A •Y AC
• SUB B • AC A
• DIV Y • AC AC – B
• STOR Y • AC AC / Y
•Y AC
One-address Instructions
Computer Architecture
Types of Instructions
• Data Transfer Instructions
Name Mnemonic Data value is
Load LD not modified
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
Computer Architecture
Return RET
Compare
CMP
(Subtract) 10110001
Test (AND) TST
00001000
Mask
00000000
Computer Architecture
I/O
• The data on which the instructions operate are not
necessarily already stored in memory.
• Data need to be transferred between processor and
outside world (disk, keyboard, etc.)
• I/O operations are essential, the way they are performed
can have a significant effect on the performance of the
computer.
Computer Architecture
Processor
DATAIN DATAOUT
SIN SOUT
- Registers
- Flags
- Device interface
Computer Architecture
STACKS
Computer Architecture
Stack Organization
Current
• LIFO
Top of Stack
TOS 0
Last In First Out
1
2
3
4
5
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Computer Architecture
Stack Organization
Current 1 6 9 0
• PUSH
Top of Stack
TOS 0
SP ← SP – 1
1
M[SP] ← DR
2
If (SP = 0) then (FULL ← 1)
3
EMPTY ← 0
4
5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Computer Architecture
Stack Organization
Current
• POP
Top of Stack
TOS 0
DR ← M[SP]
1
SP ← SP + 1
2
If (SP = 11) then (EMPTY ← 1)
3
FULL ← 0
4
5 1 6 9 0
SP 6 0 1 2 3
7 0 0 5 5
FULL EMPTY 8 0 0 0 8
9 0 0 2 5
Stack Bottom 10 0 0 1 5
Stack
Computer Architecture
Stack Organization
• Memory Stack Memory
• PUSH PC 0
SP ← SP – 1 1
2
M[SP] ← DR
• POP
AR 100
DR ← M[SP]
101
SP ← SP + 1 102
200
SP 201
202
Computer Architecture
(A B +) (D E +) C F +
Computer Architecture
PUSH 3
PUSH 4
6
MULT
PUSH 5 4
5
30
PUSH 6
3
12
42
MULT
ADD
Computer Architecture
ADDITIONAL INSTRUCTIONS
Computer Architecture
Logical Shifts
• Logical shift – shifting left (LShiftL) and shifting right
(LShiftR)
C R0 0
before: 0 0 1 1 1 0 . . . 0 1 1
after: 1 1 1 0 . . . 0 1 1 0 0
0 R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 0 0 0 1 1 1 0 . . . 0 1
Arithmetic Shifts
R0 C
before: 1 0 0 1 1 . . . 0 1 0 0
after: 1 1 1 0 0 1 1 . . . 0 1
before: 0 0 1 1 1 0 . . . 0 1 1
Rotate after: 1 1 1 0 . . . 0 1 1 0 1
C R0
before: 0 0 1 1 1 0 . . . 0 1 1
after: 1 1 1 0 . . . 0 1 1 0 0
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 1 0 1 1 1 0 . . . 0 1
R0 C
before: 0 1 1 1 0 . . . 0 1 1 0
after: 1 0 0 1 1 1 0 . . . 0 1
ENCODING OF MACHINE
INSTRUCTIONS
Computer Architecture