Ch6 PROGRAMMING THE BASIC COMPUTER (Unit-3)
Ch6 PROGRAMMING THE BASIC COMPUTER (Unit-3)
Ch6 PROGRAMMING THE BASIC COMPUTER (Unit-3)
Introduction
Machine Language
Assembly Language
Assembler
Program Loops
Subroutines
Input-Output Programming
Introduction
INTRODUCTION
Those concerned with computer architecture should
have a knowledge of both hardware and software
because the two branches influence each other.
MACHINE LANGUAGE
• Program
A list of instructions or statements for directing
the computer to perform a required data
processing task
• Machine-language
- Binary code
- Octal or hexadecimal code
• Assembly-language (Assembler)
- Symbolic code
• Fortran Program
INTEGER A, B, C
DATA A,83 / B,-23
C=A+B
END
Assembly Language
ASSEMBLY LANGUAGE
Syntax of the BC 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
Rules of the language
1. The LABEL FIELD may be empty or it may specify a
symbolic address.
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
yes
yes
Store symbol END
in address-
symbol table
together with no Go to
value of LC second
pass
Increment LC
Address Symbol Table
Assembler
LC := 0
Done ORG 100 / Origin of program is location 10
Scan next line of code
Set LC LDA SUB / Load subtrahend to AC
yes yes CMA / Complement AC
Pseudo yes no INC / Increment AC
ORG END
instr. ADD MIN / Add minuend to AC
no no STA DIF / Store difference
yes no
DEC or
HEX
HLT / Halt computer
MRI Convert MIN, DEC 83 / Minuend
Get operation code
operand
to binary
SUB, DEC -23 / Subtrahend
Valid
and set bits 2-4
non-MRI
no and store DIF, HEX 0 / Difference stored here
in location
Search address-
instr.
given by LC END / End of symbolic program
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
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
* Program Loops *
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, . -100
DEC / Initial value for a counter
.
CTR, . 0
HEX / Reserved for a counter
SUM, HEX 0 / Sum is stored here
ORG 150 / Origin of operands is HEX 150
DEC 75 / First operand
X = 0000 1111 P
cir EAC
Y = 0000 1011 0000 0000
0000 1111 0000 1111
Y AC 0001 1110 0010 1101
0000 0000 0010 1101
=0 =1 0111 1000 1010 0101
E 1010 0101
PP+X
E0
AC X
cil EAC
cil
X AC
CTR CTR + 1
0 =0
CTR Stop
Programming Arithmetic and Logic Operations
CTR - 8
P0 ORG 100
LOP, CLE / Clear E
E0 LDA Y / Load multiplier
CIR / Transfer multiplier bit to E
AC Y STA Y / Store shifted multiplier
SZE / Check if bit is zero
cir EAC BUN ONE / Bit is one; goto ONE
BUN ZRO / Bit is zero; goto ZRO
Y AC ONE, LDA X / Load multiplicand
ADD P / Add to partial product
=0 =1 STA P / Store partial product
E
CLE / Clear E
PP+X ZRO, LDA X / Load multiplicand
CIL / Shift left
E0
STA X / Store shifted multiplicand
ISZ CTR / Increment counter
AC X BUN LOP / Counter not zero; repeat loop
HLT / Counter is zero; halt
cil EAC
cil CTR, DEC -8 / This location serves as a counter
X, HEX 000F / Multiplicand stored here
X AC Y, HEX 000B / Multiplier stored here
P, HEX 0 / Product formed here
CTR CTR + 1 END
0 =0
CTR Stop
Programming Arithmetic and Logic Operations
ASSEMBLY LANGUAGE PROGRAM
- Double Precision Addition -
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(0-3) to zero
10F BUN SH4 I / Return to main program
110 MSK, HEX FFF0 / Mask operand
END
Subroutines
CHARACTER MANIPULATION
PROGRAM INTERRUPT
Tasks of Interrupt Service Routine