Coa Unit-3 Darshan
Coa Unit-3 Darshan
(COA)
GTU # 3140707
Unit-3
Programming the Basic
Computer
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 4
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
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 5
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.
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 7
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.
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 9
A.L.P. to subtract 2 numbers
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 10
First Pass of an assembler
First pass
LC ← 0
Increment LC
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 11
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
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 14
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
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 15
A.L.P. to clear the contents of hex locations 500 to 5FF with 0
1 ORG 100 /Origin of program is HEX 100
2 LDA ADS /Load first address of operands
3 STA PTR /Store in pointer
4 LDA NBR /Load minus 255
5 STA CTR /Store in counter
6 CLA /Clear accumulator
7 LOP, STA PTR I /Store zero to location pointed by PTR
8 ISZ PTR /Increment pointer
9 ISZ CTR /Increment counter
10 BUN LOP /Repeat loop again
11 HLT /Halt
12 ADS, HEX 500 /First address of operands
13 PT HEX 0 /This location reserved for pointer
14 R,
NB DEC -255 /Constant to initialized counter
15 R,
CT HEX 0 /This location reserved for a counter
16 R, END /End of symbolic program
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 16
Programming Arithmetic and
Logic operations
Section - 5
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
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 18
Subroutines
Section - 6
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.
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 20
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
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 22
Questions asked in GTU exam
Section - 8
Questions asked in GTU 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;
Prof. Krunal D. Vyas #3140707 (COA) Unit 3 – Programming the Basic Computer 24