Lecture 29 30
Lecture 29 30
Language
Reading Sections: Computer System Architecture, 3rd Edition by Morris Mano, Sections 6.1, 6.2, 6.6
CE222 − Computer Organization & Assembly Language Dr. Ghulam Abbas 1
BASIC COMPUTER INSTRUCTION SET
Hex Code
Symbol I=0 I=1 Description
AND 0xxx 8xxx AND memory word to AC
ADD 1xxx 9xxx Add memory word to AC
LDA 2xxx Axxx Load AC from memory
STA 3xxx Bxxx Store content of AC into memory
BUN 4xxx Cxxx Branch unconditionally
BSA 5xxx Dxxx Branch and save return address
ISZ 6xxx Exxx Increment and skip if zero
Q. There is no instruction
available in the Basic CLA 7800 Clear AC
CLE 7400 Clear E
Computer for subtraction, CMA 7200 Complement AC
so how are we going to CME 7100 Complement E
CIR 7080 Circulate right AC and E
perform subtraction? CIL 7040 Circulate left AC and E
INC 7020 Increment AC
SPA 7010 Skip next instr. if AC is positive
SNA 7008 Skip next instr. if AC is negative
A. Through a program SZA 7004 Skip next instr. if AC is zero
SZE 7002 Skip next instr. if E is zero
HLT 7001 Halt computer
int main ()
{
do
{
sum=sum + A[i];
i++;
}
while (i<3);
cout << sum;
}
Memory location
ORG 0 / Origin of program is HEX location 0
0 CLA / Clear AC
1 LOP, ADD PTR I / Add an operand to AC “indirectly”
2 ISZ PTR / Increment pointer
Loop
3 ISZ CTR / Increment counter
4 BUN LOP / Repeat loop again
5 STA SUM / Store sum
6 HLT / End of instructions
Pointer & 7 PTR, HEX A / Pointer to the address of operand
Loop counter 8 CTR, DEC -3 / Initial value for the loop counter
9 SUM, DEC 0 / Sum is stored here
ORG A / Origin of operands is HEX location A
A DEC 1 / First operand
Operands B DEC 4 / Second operand
C DEC 3 / Third operand
END / End of program
int main ()
{
int A[100]={1,2,3,…100};
int sum=0, i=0;
do
{
sum=sum + A[i];
i++;
}
while (i<100);
cout << sum;
}
Memory L
loicnaetion
ORG 0 / Origin of program is HEX location 0
0 CLA / Clear AC
1 LOP, ADD PTR I / Add an operand to AC “indirectly”
2 ISZ PTR / Increment pointer
Loop
3 ISZ CTR / Increment counter
4 BUN LOP / Repeat loop again
5 STA SUM / Store sum
6 HLT / End of instructions
Pointer & 7 PTR, HEX A / Pointer to the address of operand
Loop counter 8 CTR, DEC -100 / Initial value for the loop counter
9 SUM, DEC 0 / Sum is stored here
ORG A / Origin of operands is HEX location A
A DEC 1 / First operand
. . /.
Operands .
. . /.
. DEC 100 / Last operand
END / End of program
- Hardware Implementation
- Implementation of an operation in a computer
with one machine instruction
- Software Implementation
- Implementation of an operation with a program
using machine instruction set
- Usually when the operation is not included
in the instruction set
10
CE222 − Computer Organization & Assembly Language
BASIC COMPUTE INSTRUCTIONS
Hex Code
Symbol I=0 I=1 Description
AND 0xxx 8xxx AND memory word to AC
ADD 1xxx 9xxx Add memory word to AC
LDA 2xxx Axxx Load AC from memory
STA 3xxx Bxxx Store content of AC into memory
BUN 4xxx Cxxx Branch unconditionally
BSA 5xxx Dxxx Branch and save return address
ISZ 6xxx Exxx Increment and skip if zero
- One way of multiplication can be to add multiplicand 15, 11 times (15+15+15+ 15+15+ 15+ 15+15+15+ 15+15)
Program for 3-bit Opcode Processor Program in Assembly Language of Basic Computer
Please run the “7_multiplication_using_loop_2.tbt” program already
uploaded to the Dropbox ORG 0
LOOP: LDA Prod // Load Product to AC
ADD X // ADD X to AC
STA Prod // Store AC in Prod
ISZ CTR // Increment CRT and Skip Next Inst. if CRT=0
BUN LOOP // Jump to LOOP
HLT
Prod: DEC 0 // Product is stored here
X: DEC 15 // Multiplicand
CTR: DEC -11 // Loop counter (Multiplier)
END
-Although the above programs achieve the correct answer but with increased computationally complexity
- Programs on this slide compute the same answer (by adding 15 eleven times) in 11 loops.
- We will write another Program that computes the answer (15 x 11 = 165) in only 4 loops
This is how we manually multiply two binary numbers each with four significant bits:
X = 0000 1111 Y
= 0000 1011
0000 1111
0001 1110
0000 0000
0111 1000
1010 0101
X = 0000 1111
Y = 0000 1011 P
0000 1111 0000 0000
0001 1110 0000 1111
0000 0000 0010 1101
0111 1000 0010 1101
1010 0101 1010 0101
cil EAC
cil X is Shifted left 1. Start with Partial product P= 0,
2. Check the bit of Y,
X AC
3. Add X to P if the bit of Y is 1,
CTR CTR + 1 4. Circulate left the value of X.
Repeat
5. Repeat steps 2 to 4 until all
0 =0 bits of Y have been checked.
CTR Stop
ORG 0
LOOP, CLE / Clear E E0
LDA Y / Load multiplier
CIR / Transfer multiplier bit to E AC Y
STA Y / Store shifted multiplier
SZE / Check if bit is zero cir EAC
BUN ONE / E=1; go to Label ONE
BUN ZRO / E=0; go to Label ZRO Y AC
ONE, LDA X / Load multiplicand
ADD P / Add to partial product =0 E =1
STA P / Store partial product
CLE / Clear E PP+X
ZRO, LDA X / Load multiplicand E0
CIL / Shift left
STA X / Store shifted multiplicand
ISZ CTR / Increment counter AC X
BUN LOOP / Counter not zero; repeat loop
HLT / Counter is zero; halt cil EAC
cil
P, DEC 0 / Product formed here
X, DEC 15 / Multiplicand stored here X AC
Y, DEC 11 / Multiplier stored here
CTR, DEC -4 / This location serves as a counter CTR CTR + 1
END
0 =0
CTR Stop