Mod1 2(Machine Instructions)
Mod1 2(Machine Instructions)
AND PARALLELPROCESSING
Class: III ECE
Academic Year:2024 – 2025 ( Even)
VISION AND MISSION OF THE
DEPERTMENT
• VISION
• To develop Electronics and Communication Engineers by keeping
pace with changing technologies,professionalism, creativity, research
and employability.
• MISSION
• • To provide quality and contemporary education through effective
teaching - learning process that equips the
• students with adequate knowledge in Electronics and Communication
Engineering for a successful career.
• • To inculcate in students, problem solving and lifelong learning skills
that will enable the students to pursue
• higher studies and career in research.
• • To prepare engineers who possess effective communication skills,
the ability to lead a team, adhering to ethical
• values and inclination to serve the society.
PREREQUISITE
● 20EC208 - Microcontrollers and Applications
last word
b31 b30 b1 b0
•
•
•
Sign bit: b31= 0 for positive numbers
b31= 1 for negative numbers
0 0 1 2 3 0 3 2 1 0
4 4 5 6 7 4 7 6 5 4
• •
• •
• •
k k k k k k k k k k
2 -4 2 -4 2 -3 2- 2 2 - 1 2 - 4 2- 1 2 - 2 2 -3 2 -4
Branching i+8
d
Ad
d
0
NUM3,R
0
•
•
•
i + 4n - 4 Ad NUMn,R
d 0
i + 4n Mov R0,SUM
e
•
•
•
SUM
NUM
1
NUM
2
•
•
•
NUMn
SUM
N n
NUM
1
Figure 2.10. Using a loop to add n numbers. NUM
2
•
•
•
NUMn
Condition Codes
● Condition code flags
● Condition code register / status register
● N (negative)
● Z (zero)
● V (overflow)
● C (carry)
● Different instructions affect different flags
Conditional Branch
Instructions
● Example: A: 11110000
● 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
Addressing Modes
Generating Memory Addresses
● How to specify the address of branch target?
● Can we give the memory operand address
directly in a single Add instruction in the
loop?
● Use a register to hold the address of NUM1;
then increment by 4 on each pass through
the loop.
Addressing Modes
100
101 0 1 0 4
102
103
104 1 1 0 A
Addressing Modes
● Relative Address
0
● EA = PC + Relative Addr
1
PC = 2 2
100
AR = 100
101
102 1 1 0 A
Could be Positive or 103
Negative 104
(2’s Complement)
Addressing Modes
● Indexed
● 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
Addressing Modes
● Base Register
● 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
Addressing Modes
Name Assemble syntax Addressin functio
● The different r g n
ways in which Immediate #Value O erand = Value
the location of p
an operand is Register Ri E = Ri
specified in an A
Absolute (Direct) LOC E = LOC
instruction are A
referred to as Indirect (Ri ) E = [Ri ]
addressing (LOC) A = [LOC
E
modes. A ]
Index X(R i) E = [Ri ] + X
A
Basewith index (Ri ,Rj ) E = [Ri ] + [Rj ]
A
Basewith index X(R i,Rj ) E = [Ri ] + [Rj ] + X
and offse A
t
Relative X(PC) E = [PC + X
A ]
Autoincrement (Ri ) E = [Ri ] ;
+ AIncrement Ri
Autodecrement − (Ri ) Decrement R i ;
E = [Ri]
A
Indexing and Arrays
● Index mode – the effective address of the operand is
generated by adding a constant value to the
contents of a register.
● Index register
● X(Ri): EA = X + [Ri]
● The constant X may be given either as an explicit
number or as a symbolic name representing a
numerical value.
● If X is shorter than a word, sign-extension is needed.
Indexing and Arrays
● In general, the Index mode facilitates access
to an operand whose location is defined
relative to a reference point within the data
structure in which the operand appears.
● Several variations:
(Ri, Rj): EA = [Ri] + [Rj]
X(Ri, Rj): EA = X + [Ri] + [Rj]
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.
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,R
Move #NUM1,R
1 Initializatio
Clea 2
R n
LOOP r
Ad 0
(R2)+,R0
Decrement
d R
Branch> 1
LOOP
Move
0 R0,SU
M
Figure 2.16. The Autoincrement addressing mode used in the program of Figure 2.12.
Assembly Language
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
Data Transfer Instructions
Mode Assembly Register Transfer
Direct address LD ADR AC ← M[ADR]
Indirect address LD @ADR AC ← M[M[ADR]]
Relative address LD $ADR AC ← M[PC+ADR]
Immediate operand LD #NBR AC ← NBR
Index addressing LD ADR(X) AC ← M[ADR+XR]
Register LD R1 AC ← R1
Register indirect LD (R1) AC ← M[R1]
Autoincrement LD (R1)+ AC ← M[R1], R1 ← R1+1
Data Manipulation Instructions
● Arithmetic Name Mnemonic
Increment INC
● Logical & Bit Manipulation Decrement DEC
Add ADD
● Shift Subtract SUB
Multiply MUL
Divide DIV
Name Mnemonic Add with carry ADDC
Clear CLR Subtract with borrow SUBB
Complement COM Negate NEG
Name Mnemonic
AND AND Logical shift right SHR
OR OR Logical shift left SHL
Exclusive-OR XOR Arithmetic shift right SHRA
Clear carry CLRC Arithmetic shift left SHLA
Set carry SETC Rotate right ROR
Complement carry COMC Rotate left ROL
Enable interrupt EI Rotate right through carry RORC
Disable interrupt DI Rotate left through carry ROLC
Program Control Instructions
Name Mnemonic
Branch BR
Jump JMP
Skip SKP
Subtract A – B but
Call CALL don’t store the result
Return RET
Compare
CMP
(Subtract) 10110001
Test (AND) TST
00001000
Mask
00000000
Conditional Branch
Instructions
- Registers
- Flags
- Device interface
Program-Controlled I/O
Example
● Machine instructions that can check the state
of the status flags and transfer data:
READWAIT Branch to READWAIT if SIN = 0
Input from DATAIN to R1
Current
Top of Stack
● LIFO 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
Stack Organization
Current 1 6 9 0
Top of Stack
● PUSH TOS 0
SP ← SP – 1 1
M[SP] ← DR 2
3
If (SP = 0) then (FULL ← 1)
4
EMPTY ← 0 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
Stack Organization
Current
Top of Stack
● POP TOS 0
DR ← M[SP] 1
SP ← SP + 1 2
3
If (SP = 11) then (EMPTY ← 1)
4
FULL ← 0 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
Stack Organization
● Memory Stack
● PUSH PC 0
1
SP ← SP – 1 2
M[SP] ← DR
● POP AR 100
DR ← M[SP] 101
102
SP ← SP + 1
200
SP 201
202