0% found this document useful (0 votes)
3 views18 pages

Lecture 29 30

The document outlines the instruction set and programming techniques for a Basic Computer, including assembly language programs for arithmetic operations like addition and subtraction. It provides examples of how to implement loops and arithmetic operations using assembly language, along with the corresponding hexadecimal codes. Additionally, it discusses the concept of multiplication using both successive additions and partial products.

Uploaded by

SAAD MUGHAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views18 pages

Lecture 29 30

The document outlines the instruction set and programming techniques for a Basic Computer, including assembly language programs for arithmetic operations like addition and subtraction. It provides examples of how to implement loops and arithmetic operations using assembly language, along with the corresponding hexadecimal codes. Additionally, it discusses the concept of multiplication using both successive additions and partial products.

Uploaded by

SAAD MUGHAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

CE222: Computer Organization & Assembly

Language

Lecture 29, 30:


Programming the Basic Computer
Assembly language programs
Translation to Binary

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

INP F800 Input character to AC


OUT F400 Output character from AC
SKI F200 Skip on input flag
SKO F100 Skip on output flag
ION F080 Interrupt on
IOF F040 Interrupt off

CE222 − Computer Organization & Assembly Language 2


SUBTRACT USING ASSEMBLY LANGUAGE

• Assembly language program of the Basic Computer to subtract two numbers

ORG 100 / Origin of program is location 100


LDA SUB / Load subtrahend to AC
CMA / Complement AC
INC / Increment AC
ADD MIN / Add minuend to AC
STA DIF / Store difference
HLT / Halt computer
MIN, DEC 5 / Minuend
SUB, DEC 3 / Subtrahend
DIF, DEC 0 / Difference stored here
END / End of symbolic program

CE222 − Computer Organization & Assembly Language 3


TRANSLATION TO BINARY
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
Hexadecimal Code Assembly Language STA 3xxx Bxxx Store content of AC into memory
Location Content Program BUN 4xxx Cxxx Branch unconditionally
BSA 5xxx Dxxx Branch and save return address
ORG 100 ISZ 6xxx Exxx Increment and skip if zero
100 2107 LDA SUB CLA 7800 Clear AC
101 7200 CMA CLE 7400 Clear E
102 7020 INC CMA 7200 Complement AC
103 1106 ADD MIN CME 7100 Complement E
104 3108 STA DIF CIR 7080 Circulate right AC and E
CIL 7040 Circulate left AC and E
105 7001 HLT INC 7020 Increment AC
106 0005 MIN, DEC 5 SPA 7010 Skip next instr. if AC is positive
107 0003 SUB, DEC 3 SNA 7008 Skip next instr. if AC is negative
108 0000 DIF, HEX 0 SZA 7004 Skip next instr. if AC is zero
END SZE 7002 Skip next instr. if E is zero
HLT 7001 Halt computer

INP F800 Input character to AC


OUT F400 Output character from AC
SKI F200 Skip on input flag
SKO F100 Skip on output flag
ION F080 Interrupt on
IOF F040 Interrupt off

CE222 − Computer Organization & Assembly Language 4


PROGRAM LOOPS
Loop: A sequence of instructions that are executed a desired number of times,
each time with a different set of data

C++ program to add 3 numbers using a loop.

int main ()
{

int A[3]={1,4,3}; // Array of operands


int sum=0; // Accumulator
int i=0; // Loop counter

do
{
sum=sum + A[i];
i++;
}
while (i<3);
cout << sum;
}

CE222 − Computer Organization & Assembly Language 5


PROGRAM LOOPS
Symbolic Program (in the memory of Basic Computer) to add 3 numbers using a loop
Mem
Loc.# Content Comments
0 CLA / Clear AC
1 ADD 7 I / Add (indirectly) operand whose effective address is at location 7
2 ISZ 7 / Increment contents of location 7
3 ISZ 8 / Increment loop counter & skip next instruction if counter is zero
4 BUN 1 / Branch to location 1
5 STD 9 / Store answer of sum to location 12
6 HLT / End program
7 A / Pointer to the address of operand
8 -3 / Loop counter
9 /Answer of sum is stored here
A 1 /1st operand
B 4 /2nd operand
C 3 /3rd operand
CE222 − Computer Organization & Assembly Language 6
PROGRAM LOOPS

Assembly-language program to add 3 numbers using a loop

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

CE222 − Computer Organization & Assembly Language 7


PROGRAM LOOPS

C++ program to add 100 numbers:

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;
}

CE222 − Computer Organization & Assembly Language 8


PROGRAM LOOPS

Assembly-language program to add 100 numbers:

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

CE222 − Computer Organization & Assembly Language 9


PROGRAMMING ARITHMETIC AND
LOGIC OPERATIONS

Implementation of Arithmetic and Logic Operations

- 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

Software Implementation example for Basic Computer:


- Subtraction
- Multiplication

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

CLA 7800 Clear AC


CLE 7400 Clear E
CMA 7200 Complement AC
CME 7100 Complement E
CIR 7080 Circulate right AC and E
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
SZA 7004 Skip next instr. if AC is zero
SZE 7002 Skip next instr. if E is zero
HLT 7001 Halt computer

INP F800 Input character to AC


OUT F400 Output character from AC
SKI F200 Skip on input flag
SKO F100 Skip on output flag
ION F080 Interrupt on
IOF F040 Interrupt off

CE222 − Computer Organization & Assembly Language 11


MULTIPLICATION PROGRAM USING LOOPS
- Example: 15 x 11 = 165 X= (15)10
Y= (11)10

- 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

To test this Basic Computer program use the file “Multiplication


using Successive Additions” uploaded to Dropbox.

-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

CE222 − Computer Organization & Assembly Language 12


MULTIPLICATION
X holds the multiplicand
Y holds the multiplier

X = (0000 1111)2 = (15)10


Y = (0000 1011)2 = (11)10

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

CE222 − Computer Organization & Assembly Language 13


MULTIPLICATION USING PARTIAL PRODUCT
X holds the multiplicand
Y holds the multiplier
P holds the partial product

X = (0000 1111)2 = (15)10


Y = (0000 1011)2 = (11)10

This is how we multiply manually using partial product

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

CE222 − Computer Organization & Assembly Language 14


MULTIPLICATION USING PARTIAL PRODUCT
X (multiplicand) = 0000 1111
Y (multiplier) = 0000 1011
P (partial product) = 0000 0000

Step by step process of multiplication using partial product


Name of
Comment Value
variable
Start with a partial product equal to zero P0 = 0000 0000
Use the original value of X X= 0000 1111
Because the 1st bit of Y = 1, add X to P0 (P1 = P0 + X) P1 = 0000 1111
Circulate X to left X= CIL (X) = 0001 1110
Because the 2nd bit of Y = 1, add X to P1 (P2 = P1 + X) P2 = 0010 1101
Circulate X to left X= CIL (X) = 0011 1100
As the 3rd bit of Y = 0, partial product remains unchanged (P3 = P2) P3 = 0010 1101
Circulate X to left X= CIL (X) = 0111 1000
Because the 4th bit of Y = 1, add X to P3 (P4 = P3 + X) P4 = 1010 0101
P4 is the final product

CE222 − Computer Organization & Assembly Language 15


FLOWCHART OF MULTIPLICATION PROGRAM
CTR  - 4
P0
X holds the multiplicand
Y holds the multiplier
E0 P holds the product

AC  Y Example with four significant digits

Check the X = 0000 1111 P


cir EAC bit of Y Y = 0000 1011 0000 0000
0000 1111 0000 1111
Y  AC 0001 1110 0010 1101
0000 0000 0010 1101
0111 1000 1010 0101
=0 E =1
1010 0101
PP+X add X to P if
the bit in Y=1
E0
The process of multiplication
AC  X
using partial product:

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

CE222 − Computer Organization & Assembly Language 16


PROGRAM FOR MULTIPLICATION USING
PARTIAL PRODUCT
CTR  - 8
P0

ORG 0
LOOP, CLE / Clear E E0
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 PP+X
ZRO, LDA X / Load multiplicand E0
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

CE222 − Computer Organization & Assembly Language 17


PROGRAM FOR MULTIPLICATION USING
PARTIAL PRODUCT

• To test this Basic Computer program use the file


“Multiplication using Partial Product” uploaded to
MS Teams.

CE222 − Computer Organization & Assembly Language 18

You might also like