[go: up one dir, main page]

0% found this document useful (0 votes)
8 views30 pages

Unit 2 Notes

The document provides notes on programming the basic computer, covering machine language, assembly language, and the role of assemblers. It includes instruction sets, comparisons of programming languages, and examples of program loops and arithmetic operations. Additionally, it discusses subroutines and their implementation in assembly language.

Uploaded by

Ekta chasta
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)
8 views30 pages

Unit 2 Notes

The document provides notes on programming the basic computer, covering machine language, assembly language, and the role of assemblers. It includes instruction sets, comparisons of programming languages, and examples of program loops and arithmetic operations. Additionally, it discusses subroutines and their implementation in assembly language.

Uploaded by

Ekta chasta
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/ 30

lOMoARcPSD|55900809

Unit 2 - unit 2 notes

computer architecture (Rajasthan Technical University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

L-12
Programming the Basic Computer 1

PROGRAMMING THE BASIC COMPUTER

Introduction

Machine Language

Assembly Language

Assembler

Program Loops

Programming Arithmetic and Logic Operations

Subroutines

Input-Output Programming

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 2 Introduction

INTRODUCTION
Those concerned with computer architecture should
have a knowledge of both hardware and software
because the two branches influence each other.

Instruction Set of the Basic Computer


Symbol Hexa code Description
AND 0 or 8 AND M to AC m: effective address
ADD 1 or 9 Add M to AC, carry to E M: memory word (operand)
LDA 2 or A Load AC from M found at m
STA 3 or B Store AC in M
BUN 4 or C Branch unconditionally to m
BSA 5 or D Save return address in m and branch to m+1
ISZ 6 or E Increment M and skip if zero
CLA 7800 Clear AC
CLE 7400 Clear E
CMA 7200 Complement AC
CME 7100 Complement E
CIR 7080 Circulate right E and AC
CIL 7040 Circulate left E and AC
INC 7020 Increment AC, carry to E
SPA 7010 Skip if AC is positive
SNA 7008 Skip if AC is negative
SZA 7004 Skip if AC is zero
SZE 7002 Skip if E is zero
HLT 7001 Halt computer
INP F800 Input information and clear flag
OUT F400 Output information and clear flag
SKI F200 Skip if input flag is on
SKO F100 Skip if output flag is on
ION F080 Turn interrupt on
IOF F040 Turn interrupt off

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 3 Machine Language

MACHINE LANGUAGE
Program
A list of instructions or statements for directing
the computer to perform a required data
processing task

Various types of programming languages


- Hierarchy of programming languages

• Machine-language
- Binary code
- Octal or hexadecimal code

• Assembly-language (Assembler)
- Symbolic code

• High-level language (Compiler)

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 4 Machine Language

COMPARISON OF PROGRAMMING LANGUAGES


• Binary Program to Add Two Numbers • Hexa program
Location Instruction
Location Instruction Code
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

• Program with Symbolic OP-Code • Assembly-Language Program

Location Instruction Comments ORG 0 /Origin of program is location 0


000 LDA 004 Load 1st operand into AC LDA A /Load operand from location A
001 ADD 005 Add 2nd operand to AC ADD B /Add operand from location B
002 STA 006 Store sum in location 006 STA C /Store sum in location C
003 HLT Halt computer HLT /Halt computer
004 0053 1st operand A, DEC 83 /Decimal operand
005 FFE9 2nd operand (negative) B, DEC -23 /Decimal operand
006 0000 Store sum here C, DEC 0 /Sum stored in location C
END /End of symbolic program

• Fortran Program
INTEGER A, B, C
DATA A,83 / B,-23
C=A+B
END

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 5 Assembly Language

ASSEMBLY LANGUAGE
Syntax of the assembly language
Each line is arranged in three columns called fields
Label field
- May be empty or may specify a symbolic
address consists of up to 3 characters
- Terminated by a comma
Instruction field
- Specifies a machine or a pseudo instruction
- May specify one of
* Memory reference instr. (MRI)
MRI consists of two or three symbols separated by spaces.
ADD OPR (direct address MRI)
ADD PTR I (indirect address MRI)
* Register reference or input-output instr.
Non-MRI does not have an address part
* Pseudo instr. with or without an operand
Symbolic address used in the instruction field must be
defined somewhere as a label
Comment field
- May be empty or may include a comment

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 6 Assembly Language

PSEUDO-INSTRUCTIONS
ORG N
Hexadecimal number N is the memory loc.
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 the binary
HEX N
Hexadecimal number N to be converted to the binary

Example: Assembly language program 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 83 / Minuend
SUB, DEC -23 / Subtrahend
DIF, HEX 0 / Difference stored here
END / End of symbolic program

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 7 Assembly Language

TRANSLATION TO BINARY

Hexadecimal Code
Location Content Symbolic Program

ORG 100
100 2107 LDA SUB
101 7200 CMA
102 7020 INC
103 1106 ADD MIN
104 3108 STA DIF
105 7001 HLT
106 0053 MIN, DEC 83
107 FFE9 SUB, DEC -23
108 0000 DIF, HEX 0
END

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 8

Representation of Symbolic Program in


Memory PL3, LDA SUB I

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 9

Computer Representaion of Line of


Code

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

L-13 & L-14


Programming the Basic Computer 10 Assembler

ASSEMBLER - FIRST PASS -


Assembler
Source Program - Symbolic Assembly Language Program
Object Program - Binary Machine Language Program
Two pass assembler
1st pass: generates a table that correlates all user defined
(address) symbols with their binary equivalent value
2nd pass: binary translation

First pass First pass

LC := 0

Scan next line of code Set LC


yes
no no
Label ORG

yes
yes
Store symbol END
in address-
symbol table
together with no Go to
value of LC second
pass
Increment LC

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 11 Assembler

ASSEMBLER - SECOND PASS -


Second Pass
Machine instructions are translated by means of table-lookup procedures;
(1. Pseudo-Instruction Table, 2. MRI Table, 3. Non-MRI Table
4. Address Symbol Table)
Second pass

LC <- 0
Done
Scan next line of code
Set LC

yes yes
Pseudo yes no
ORG END
instr.

no no
DEC or
yes no HEX
MRI Convert
operand
Get operation code to binary
and set bits 2-4 Valid no
non-MRI and store
instr. in location
Search address- given by LC
symbol table for yes
binary equivalent
of symbol address
and set bits 5-16
Store binary Error in
equivalent of line of
yes no instruction code
I in location
given by LC
Set Set
first first
bit to 1 bit to 0

Assemble all parts of


binary instruction and Increment LC
store in location given by LC

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

L-15
Programming the Basic Computer 12 Program Loops

PROGRAM LOOPS
Loop: A sequence of instructions that are executed many times,
each with a different set of data
Fortran program to add 100 numbers: DIMENSION A(100)
INTEGER SUM, A
SUM = 0
DO 3 J = 1, 100
3 SUM = SUM + A(J)

Assembly-language program to add 100 numbers:


ORG 100 / Origin of program is HEX 100
LDA ADS / Load first address of operand
STA PTR / Store in pointer
LDA NBR / Load -100
STA CTR / Store in counter
CLA / Clear AC
LOP, ADD PTR I / Add an operand to AC
ISZ PTR / Increment pointer
ISZ CTR / Increment counter
BUN LOP / Repeat loop again
STA SUM / Store sum
HLT / Halt
ADS, HEX 150 / First address of operands
PTR, HEX 0 / Reserved for a pointer
NBR, DEC -100 / Initial value for a counter
CTR, HEX 0 / Reserved for a counter
SUM, HEX 0 / Sum is stored here
ORG 150 / Origin of operands is HEX 150
DEC 75 / First operand
.
.
.
DEC 23 / Last operand
END / End of symbolic program

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 13 Programming Arithmetic and Logic Operations

PROGRAMMING ARITHMETIC AND LOGIC OPERATIONS

Implementation of Arithmetic and Logic Operations

- Software Implementation
- Implementation of an operation with a program
using machine instruction set
- Usually when the operation is not included
in the instruction set
- Long programs both in number of instructions and time

- Hardware Implementation
- Implementation of an operation in a computer
with one machine instruction
- Costly

Software Implementation example:

* Multiplication Program

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 14

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 15 Programming Arithmetic and Logic Operations


ASSEMBLY LANGUAGE PROGRAM
- Logic and Shift Operations -
• Logic operations
- BC instructions : AND, CMA, CLA
- Program for OR operation x+y=(x’y’)’
LDA A / Load 1st operand
CMA / Complement to get A’
STA TMP / Store in a temporary location
LDA B / Load 2nd operand B
CMA / Complement to get B’
AND TMP / AND with A’ to get A’ AND B’
CMA / Complement again to get A OR B
• Shift operations - BC has Circular Shift only
- Logical shift-right operation - Logical shift-left operation
CLE CLE
CIR CIL

- Arithmetic right-shift operation


CLE / Clear E to 0
SPA / Skip if AC is positive
CME / AC is negative
CIR / Circulate E and AC

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 16 Subroutines

SUBROUTINES
Subroutine
- A set of common instructions that can be used in a program many times.
- Subroutine linkage : a procedure for branching
to a subroutine and returning to the main program
Example
Loc. ORG 100 / Main program
100 LDA X / Load X
101 BSA SH4 / Branch to subroutine
102 STA X / Store shifted number
103 LDA Y / Load Y
104 BSA SH4 / Branch to subroutine again
105 STA Y / Store shifted number
106 HLT
107 X, HEX 1234
108 Y, HEX 4321
/ Subroutine to shift left 4 times
109 SH4, HEX 0 / Store return address here
10A CIL / Circulate left once
10B CIL
10C CIL
10D CIL / Circulate left fourth time
10E AND MSK / Set AC(13-16) to zero
10F BUN SH4 I / Return to main program
110 MSK, HEX FFF0 / Mask operand
END

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

Programming the Basic Computer 17 Subroutines

Input-Output Programming
I/O Programming
- A binary coded-character enters the computer when an INP instruction is
executed.
- A binary coded-character is transferred to the output device when an
OUT instruction is executed.
Example

Computer Organization Computer Architectures Lab


Downloaded by Ekta Chasta (ektachasta15@gmail.com)
lOMoARcPSD|55900809

L-16

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

L-17

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

L-18

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner


lOMoARcPSD|55900809

Downloaded by Ekta Chasta (ektachasta15@gmail.com) Scanned by CamScanner

You might also like