0% found this document useful (0 votes)
45 views44 pages

Computer Organisation and Architecture

The document discusses programming the basic computer by covering topics like machine language, assembly language, assemblers, program loops, arithmetic and logic operations, and I/O programming. It provides examples of machine code, assembly language programs, and how assemblers work in two passes to translate assembly code to machine code. It also discusses implementing loops and arithmetic operations in programs.

Uploaded by

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

Computer Organisation and Architecture

The document discusses programming the basic computer by covering topics like machine language, assembly language, assemblers, program loops, arithmetic and logic operations, and I/O programming. It provides examples of machine code, assembly language programs, and how assemblers work in two passes to translate assembly code to machine code. It also discusses implementing loops and arithmetic operations in programs.

Uploaded by

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

Computer Organization & Architecture

(COA)
GTU # 3140707

Unit-3
Programming the Basic
Computer

Computer Engineering Department


 Outline
Looping
• Machine Language
• Assembly Language
• Assembler
• Program loops
• Programming Arithmetic and Logic operations
• Subroutines
• I-O Programming
Machine Language
Section - 1
Categories of programs
 Binary code  Octal or hexadecimal code
 This is a sequence of instructions and operands  This is an equivalent translation of the binary
in binary that list the exact representation of code to octal or hexadecimal representation.
instructions as they appear in computer
memory.

Location Instruction Code Location Instruction


0 0010 0000 0000 0100 000 2004
1 0001 0000 0000 0101 001 1005
10 0011 0000 0000 0110 002 3006
11 0111 0000 0000 0001 003 7001
100 0000 0000 0101 0011 004 0053
101 1111 1111 1110 1001 005 FFE9
110 0000 0000 0000 0000 006 0000
Categories of programs
 Symbolic code  High-level programming languages
 The user employs symbols (letters, numerals, or  These are special languages developed to reflect
special characters) for the operation part, the the procedures used in the solution of a problem
address part, and other parts of the instruction rather than be concerned with the computer
code. hardware behavior. E.g. Fortran, C++, Java, etc.
 Each symbolic instruction can be translated into  The program is written in a sequence of
one binary coded instruction by a special statements in a form that people prefer to think
program called an assembler and language is in when solving a problem.
referred to as an assembly language program.  However, each statement must be translated into
Location Instruction Comment a sequence of binary instructions before the
000 LDA 004 Load first operand into AC
program can be executed in a computer.
001 ADD 005 Add second operand to AC
002 STA 006 Store sum in location 006 INTEGER A, B, C
003 HLT Halt computer DATA A, 83 B,-23
004 0053 First operand C = A + B
005 FFE9 Second operand (negative) END
006 0000 Store sum here
Assembly Language
Section - 2
Pseudo Instruction
 A pseudo instruction is not a machine instruction but rather an instruction to the assembler
giving information about some phase of the translation.

Symbol Information for the Assembler


Hexadecimal number N is the memory location for the
ORG N
instruction or operand listed in the following line.
END Denotes the end of symbolic program.
DEC N Signed decimal number N to be converted to binary.
HEX N Hexadecimal number N to be converted to binary
Assembler
Section - 3
Assembler
 An assembler is a program that accepts a symbolic language program and produces its binary
machine language equivalent.
 The input symbolic program is called the source program and the resulting binary program is
called the object program.
 The assembler is a program that operates on character strings and produces an equivalent
binary interpretation.
A.L.P. to subtract 2 numbers

Location Instructio Symbol Location


n
MIN 106
ORG 100
SUB 107
100 LDA SUB
DIF 108
101 CMA
102 INC
103 ADD MIN
104 STA DIF
105 HLT
106 MIN, DEC 83
107 SUB, DEC -23
108 DIF, HEX 0
END
First Pass of an assembler
First pass

LC ← 0

Scan next line of code Set LC


yes
no OR no
Label
G
yes
EN yes
Store address in D
symbol table
no
together with Go to
value of LC second
pass

Increment LC
Second pass

Second Pass
LC ← 0

of an
Scan next line of code Set LC Done
Yes Yes
No EN
assembler
Pseudo- Yes OR
instruction G D
No
No
No DEC or HEX Convert
Yes MRI operand to
binary and
Get operation Valid non- store in
No
code and set MRI location
bits 2-4 instruction given by LC

Search address- Yes


symbol table for Store binary Error in
binary equivalent of equivalent of line of
symbolic address instruction in code
and set bits 5-16 location given
by LC
Yes No
I
Set first Set first
bit to 1 bit to 0

Assemble all parts of binary


instruction and store in Increment LC
location given by LC
Program loops
Section - 4
Program Loops
 A program loop is a sequence of instructions that are executed many times, each time with a
different set of data.
 A system program that translates a program written in a high-level programming language to
a machine language program is called a compiler.
A.L.P. to add 100 numbers
1 ORG 100 /Origin of program is HEX 100 13 ADS, HEX 150 /First address of operands
2 LDA ADS /Load first address of operands 14 PTR, HEX 0 /This location reserved for pointer
3 STA PTR /Store in pointer 15 NBR, DEC -100 /Constant to initialized counter
4 LDA NBR /Load minus 100 16 CTR, HEX 0 /This location reserved for a counter
5 STA CTR /Store in counter 17 SUM, HEX 0 /Sum is store here
6 CLA /Clear accumulator 18 ORG 150 /Origin of operands is HEX 150
7 LOP, ADD PTR I /Add an operand to AC 19 DEC 75 /First operand
8 ISZ PTR /Increment pointer .
9 ISZ CTR /Increment counter .
.
10 BUN LOP /Repeat loop again 118 DEC 23 /Last operand
11 STA SUM /Store sum 119 END /End of symbolic program
12 HLT /Halt
Multiplication algorithm for
Unsigned Number
Section - 5
Programming Arithmetic and
Logic operations
Section - 5
 Some Computer perform a given operation with one machine instruction; other may a require
a large number of machine instruction to perform the same operation.

 There are four basics operation add, Subtract, multiply, and divide.
 Operations that are implemented in a computer with one machine instruction are said to be
implemented by hardware.
 Operation implemented by a set of instruction that constitute a program are said to be
implemented by software.
 Software implementation results in long programs both in number of instruction and in
Execution time.
Double-Precision Addition
 When two 16-bit unsigned numbers are multiplied, the result is a 32-bit product that must be
stored in two memory words. A number stored in two memory words is said to have double
precision.
A.L.P. to Add Two Double-Precision Numbers
1 ORG 100 /Origin of program is HEX 100
2 LDA AL /Load A low
3 ADD BL /Add B low, carry in E
4 STA CL /Store in C low
5 CLA /Clear AC
6 CIL /Circulate to bring carry into AC(16)
7 ADD AH /Add A high and carry
8 ADD BH /Add B high
9 STA CH /Store in C high
10 HLT /Halt
AL Location of Operands
AH
BL
BH
CL
CH
Logic Operations
 The basic Computer has three machine instructions that perform logic operations:
 AND, CMA, and CLA.
 For Example
 LDA A //Load first operand A
 CMA //Complement to Get A
 STA TMP // Store in a Temporary location
 LDA B // Load Second operand B
 CMA // Complement to Get B
 AND TMP // AND operation of A and B
 CMA // Complement of AND operation
Shift Operations
 The logical Shift requires that zeroes be added to the extreme positions. This is easily
accomplished by clearing E(Extended clear to AC) and Circulating the AC and E.
 Logical Shift – right operations we need the two instructions.
 CLE
 CIR
 Logical Shift – left operation We need the two instructions
 CLE
 CIL
Subroutines
Subroutine with example
 A set of common instructions that can
be used in a program many times is
called a subroutine. ORG 100
 Each time that a subroutine is used in 100 LDA X 109 SH4, HEX 0
the main part of the program, a branch 101 BSA SH4 10A CIL
is executed to the beginning of the 102 STA X 10B CIL
subroutine. 103 LDA Y 10C CIL
 After the subroutine has been executed, 104 BSA SH4 10D CIL
a branch is made back to the main 105 STA Y 10E AND MSK
program. 106 HLT 10F BUN SH4 I
 A subroutine consists of a self 107 X, HEX 1234 110 MSK, HEX FFF0
contained sequence of instructions that 108 Y, HEX 4321 END
carries a given task.
Subroutine Parameters and
Data Linkage
I-O Programming
Section - 7
A.L.P. to input one character & output one character

Input Output
1 Program
ORG 100 /Origin of program is HEX 100 1 Program
ORG 100 /Origin of program is HEX 100
2 CIF, SKI /Check input flag 2 LDA CHR /Load character into AC
3 BUN CIF /Flag = 0, branch to check again 3 COF, SKO /Check output flag
4 INP /Flag = 1, input character 4 BUN COF /Flag = 0, branch to check again
5 OUT /Print character 5 OUT /Flag = 1, output character
6 STA CHR /Store character 6 HLT
7 HLT
7 CHR, HEX 0057 /Character is “W”
8 CHR, - /Store character here
8 END
9 END
Questions asked in CVMU
exam
Section - 8
Questions asked in CVMU exam
1. What is an Assembler? With clear flowcharts for first and second pass, explain its working.
2. Write an assembly language program to add 10 numbers from memory.
3. Write a brief note on: Subroutine call and return.
4. Write an ALP for multiplying 3 integers stored in register stack.
5. Write an assembly program to multiply two positive numbers.
6. What is machine language? How it differs from assembly language?
7. Define pseudo-instruction.
8. For the following C language code, write assembly language program:
int a, b, c;
a = 83; //plus 83
b = -23; //minus 23
c = a + b;

You might also like