0% found this document useful (0 votes)
9 views24 pages

Basic Computer Programming Concepts

Uploaded by

purvajvaidya
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)
9 views24 pages

Basic Computer Programming Concepts

Uploaded by

purvajvaidya
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

Computer Organization &

Architecture (COA)
GTU # 3140707

Unit-3
Programming the
Basic Computer

Prof. Krunal D. Vyas


Computer Engineering
Department
Darshan Institute of Engineering & Technology, Rajkot
[Link]@[Link]
9601901005
 Looping
Outline
• Machine Language
• Assembly Language
• Assembler
• Program loops
• Programming Arithmetic and Logic operations
• Subroutines
• I-O Programming
• Questions asked in GTU exam
Machine Language
Section - 1
Categories of programs
 Binary code  Octal or hexadecimal code
 This is a sequence of instructions and  This is an equivalent translation of the
operands in binary that list the exact binary code to octal or hexadecimal
representation of instructions as they representation.
appear in computer memory.

Locati Instruction Code Location Instruction


on 000 2004
0 0010 0000 0000 0100 001 1005
1 0001 0000 0000 0101 002 3006
10 0011 0000 0000 0110 003 7001
11 0111 0000 0000 0001 004 0053
100 0000 0000 0101 0011 005 FFE9
101 1111 1111 1110 1001 006 0000
110 0000 0000 0000 0000

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,  These are special languages developed
numerals, or special characters) for to reflect the procedures used in the
the operation part, the address part, solution of a problem rather than be
and other parts of the instruction code. concerned with the computer
 Each symbolic instruction can be hardware behavior. E.g. Fortran, C++,
translated into one binary coded Java, etc.
instruction by a special program called  The program is written in a sequence
an assembler and language is referred of statements in a form that people
to as an
Location assembly language
Instructio program.
Comment
prefer to think in when solving a
n problem.
 However, each statement must be
000 LDA 004 Load first operand into
AC
translated into a sequence of binary
INTEGER
instructions beforeA,
theB, C
program can be
001 ADD 005 Add second operand to executed in a computer.
DATA A, 83 B,-23
AC
C = A + B
002 STA 006 Store sum in location
006 END
003 HLT Halt computer
004 0053
Prof. Krunal D. Vyas
First operand
#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.

Symbol Information for the Assembler


Hexadecimal number N is the memory location
ORG N for the 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

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

Locatio Instructi Symbol Location


n on 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

Prof. Krunal D. Vyas #3140707 (COA)  Unit 3 – Programming the Basic Computer 10
First Pass of an assembler
First pass

LC ← 0

Scan next line of code Set LC


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

Increment LC

Prof. Krunal D. Vyas #3140707 (COA)  Unit 3 – Programming the Basic Computer 11
Second pass

Second
LC ← 0

Pass
Scan next line of code Set LC Done
Yes Yes
Pseudo-

of an
Yes OR No EN
instructio
G D
n No
No

assembler
Convert
No DEC or HEX
MRI operand
Yes
to binary
Get Valid and store
operation non-MRI No in location
code and instructio given by
set bits 2-4 n LC
Search address-
symbol table for Yes
Store Error
binary binary in line
equivalent of equivalent of
symbolic of code
address and set instruction
bits 5-16 in location
Yes No given by LC
I
Set Set
first first
bit to bit to
1
Assemble all 0parts of
binary instruction and
Increment LC
store in 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.

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 10013 ADS, HEX 150 /First address of operands
2 14 PTR, HEX 0 /This location reserved for point
LDA ADS /Load first address of operands
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 cou
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 /Store
I 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 ORG 100
subroutine. 100 LDA X 109 SH4, HEX 0
 Each time that a subroutine is 101 BSA SH4 10A CIL
used in the main part of the 102 STA X 10B CIL
program, a branch is executed 103 LDA Y 10C CIL
to the beginning of the 104 BSA SH4 10D CIL
subroutine. 105 STA Y 10E AND MSK
 After the subroutine has been 106 HLT 10F BUN SH4 I
executed, a branch is made 107 X, HEX 1234 110 MSK,HEX FFF0
back to the main program. 108 Y, HEX 4321 END
 A subroutine consists of a self
contained sequence of
instructions that 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 aga
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

You might also like