1.4 Instructions - Instruc Seq
1.4 Instructions - Instruc Seq
P Institute of Technology
Coimbatore – 641
048
Unit - 1
C = A + B-> C<-[A]+[B]
Addition of 2 numbers in high level language.
Three Address instruction format
Operation Source1,Source2,Destination
Can be represented as
Add A,B,C
A,B are source operands
C Destination operands,Add is the operation to
be performed on the operands.
32-bit address space, a 3-address instruction is
too large to fit in oneword for a
reasonableword length.
• Three-Address Instructions
• ADD R1, R2, R3 R1 ← R2 + R3
• Two-Address Instructions
• ADD R1, R2 R1 ← R1 + R2
• One-Address Instructions
• ADD M AC ← AC + M[AR]
• Zero-Address Instructions
• ADD TOS ← TOS + (TOS – 1)
• RISC Instructions
• Lots of registers. Memory is restricted to Load &
Store
Opco Operand(s) or
de Address(es)
Instruction Formats
AddressContents Assumptions:
- One memory operand
i
Begin execution here Move
A,R0
i+ 4 AddB,R0 3-instruction
program per instruction
R0,C segment - 32-bit word length
i+ 8 Move
- Memory is byte
addressable
A - Full memory address
can be directly specified
B Data
the for in a single-word instruction
program
Two-phase
C procedure
-Instruction
fetch
-Instruction
Figure 2.8. A program for C ¬ [A] + [B].
The processor contains a register
program counter (PC) - holds the address of
the instruction to be executed next.
(i.e) i,i+4,i+8,i+12.
Instruction Fetch-:
• Instruction fetched from the memory
loc – address is in PC
• Place the instruction to the
IR(Instruction Register)
Instruction Execute:
• Fetching operands from mem or pcr
registers
• Performing arithmetic and logic
operations.
• Storing the result in destination
i Move
NUM1,R0
Branching i+4 AddNUM2,R0
i+8 AddNUM3,R0
•
•
• n,R0
i+4n-4 AddNUM
i+4n Move
R0,SUM
•
•
SUM •
NUM1
NUM2
•
•
NUMn •
•
•
NUM n •
• Loop starts at location loop & ends at
instruction Branch>0
• During each pass ,address of next list entry
is determined and it is fetched & added to R0.
• Register R1- counter determines number of
times the loop to be executed.
• [N] – stored in R1.
• Decrement R1- reduces the [R1] by 1 each
time through the loop.
• Execution repeated- decrement operation >0
Branch Instruction
This insruction loads a new value into the PC.
Pcr fetches and executes the instruction at this
new address – branch target
Instead of fetches the instruction present,next to
branch instruction.
Conditional branches- only if a specified condtion
is satisfied.
If not PC incremented – fetches the next
instruction in sequential order.
Branch > 0 LOOP
Cond branch instruction causes a branch to LOOP
– if the result R1>0
Repeated till R1<0.
After nth pass, MOVE instruction fetched and
executed.
Condition codes:
Pcr – results of various operations – conditional
branch instructions.
This information – individual bits called
conditional code flags.
These flags – Spl pcr register called status
register or condition code register.
Flag value- 0 or 1 based on operation
performed.
• N (negative) Set to 1 if the result is negative;
otherwise, cleared to 0
• Z (zero) Set to 1 if the 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
Condition Codes
• A: 1 1 1 1 0 0 0 0 +(−B): 1 1 1 0 1 1 0 0
• B: 0 0 0 1 0 1 0 0
11011100
C=1 Z=0
S=1
V=0
Status Bits
Cn-1 A B
Cn
ALU F
V Z S C
Fn-1
Zero Check
Generating memory addresses
Memory operand address – cannot be
given directly in a add instruction
otherwise
Need to be modified on each pass
through the loop.
Suppose Ri holds address of an
operand.
If it is loaded with the address NUM1
& is incremented by 4 on each pass.
Thank You!