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

Coa Unit-3 Darshan

Uploaded by

cidav39798
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)
34 views24 pages

Coa Unit-3 Darshan

Uploaded by

cidav39798
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/ 24

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
krunal.vyas@darshan.ac.in
9601901005
 Outline
Looping
• 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 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

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.

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

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

Location Instruction Symbol Location


ORG 100 MIN 106
100 LDA SUB SUB 107
101 CMA DIF 108
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
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

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

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.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy