You are on page 1of 12

Lecture 2: Instructions

EEE 105: Computer Organization

Memory Locations

K (kilo) = 210 = 1024


M (mega) = 220 = 1048576
G (giga) = 230 = 1073741824

b n-1

b1 b0

...

Each data has an address or distinct


name for the location
Memory with k address bits have 2k
addresses
Memory size suffixes

...

Referred to as words
n is the word length

Word
Address

...

Numbers, character data, instructions


are all stored in computer's memory
Memory is organized so data is
accessed by a group of n bits

2 -1

Encoded information and Byte Addressability

Characters
8bits

8bits

8bits

8bits

ASCII

ASCII

ASCII

ASCII

Signed integer
b 31 b 30

...

b1 b0

Common to group data into 8-bit


chunks called bytes
Word size may not necessarily be
equal to 1 byte, but typically
multiple of bytes

sign bit
Machine instruction
8bits

24 bits

opcode

addressing information

Referred to as words
n is the word length

If word size is not equal to byte, then


possible memory alignment issues

ex. Fetching an instruction in byteaddressable memory by using an


address which is not a multiple of the
word length

Byte ordering
For data spanning multiple bytes
May differ from one ISA to another
Word
addr

32-bit integer
0xABCD1234
bit 31
Word
addr
0
1

bit 0
Big Endian
34 12 CD AB

Byte addr

Word
addr
0

Little Endian
AB CD 12 34

1
4

Memory Operations
Instructions and data are stored in memory
Must be transferred to processor for execution
Results of execution also placed back to memory for later use

Two basic memory operations:


Load / Read / Fetch copies the contents of a memory address to
the processor
Store / Write writes processor data to a memory address

Instructions

Instruction types

Instruction Sequencing
Addr

Move A,R0

i+1

Add B,R0

i+2

Move R0,C

3-instruction
program
segment

A
Data for
program

...

Fetch instruction fetched from


memory to processor
Execute instruction executed:
fetch operands, perform
operation, store result

...

start
here

...

Special CPU register named


Program Counter (PC) holds
address of instruction to be
executed
PC incremented after
instruction execution to
prepare for next instruction
(straight-line sequencing)
Instruction Execution

Memory contents

Branch Instructions

Two kinds:
Conditional will only
modify PC value if a
specific condition is met
Unconditional

Program Loop

Clear R0
LOOP

Determine addr of
"Next" no and add
"Next" no to R0
Decrement R1
Branch>0 LOOP
Move R0,SUM

...

Instructions that load a


new value in the PC
Gives capability to break
straight-line execution
Commonly used for
constructing loops and
if-else statements

Move N,R1

SUM
N
NUM1
NUM2

...

...

Condition Codes
Processor keeps track of some information about results of
some instructions
These information are stored in condition code flags
Frequently grouped together in a register called condition
code or status register
Used by conditional branch instructions to make decision
Commonly used flags:
N (negative) set to 1 if result is negative; otherwise cleared to 0
Z (zero) set to 1 if result is 0; otherwise cleared to 0
V (overflow) set to 1 if arithmetic overflow occurs; otherwise cleared
to 0
C (carry) set to 1 if a carry-out results from the operation; otherwise
cleared to 0

10

Addressing Modes
Register Operand is the contents of a CPU register
Absolute Operand is in a memory location specified explicitly in the
instruction
Immediate Operand itself specified explicitly in the instruction
Indirect Effective address of operand (in memory) is the contents of a
register or main memory location whose address is specified in the instruction
Index Effective address of operand (in memory) is generated by adding a
constant value (index) to the contents of a register (base)
Autoincrement Effective address of operand is contents of register
specified in the instruction. After accessing the operand, the contents of said
register are incremented (to point to next item in list)
Autodecrement

11

Reference

Computer Organization, 4th ed. Hamacher et al

12

You might also like