Chapter 6 (Comp. Arch)
Chapter 6 (Comp. Arch)
Chapter 6 (Comp. Arch)
ELE5361
Computer
Introduction
Machine Language
Assembly Language
Assembler
Program Loops
Subroutines
Input-Output Programming
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
Computer Arch. & Org.F040 Turn interrupt off
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
• 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
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
ADD OPR
separated (direct address MRI)
by spaces.
ADD PTR I (indirect address MRI)
Symbolic address used in the instruction field must be
defined somewhere as a label
* Register reference or input-output instr.
Non-MRI does not have an address part
* Pseudo instr. with or without an operand
Comment field
- May be empty or may include a comment
Computer Arch. & Org.
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
TRANSLATION TO BINARY
Hexadecimal Code
Symbolic Program
Location Content
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
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
First
2nd pass
pass: binary translation
First pass
LC := 0
yes
yes
Store symbol END
in address-
symbol table
together with no Go to
value of LC second
pass
Increment 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
symbol table for LC
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 bit to 0
1
Assemble all parts of
binary instruction and Increment LC
store in location
given by LC
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 / Add an operand to AC
I / Increment pointer
ISZ PTR / Increment counter
ISZ CTR / Repeat loop again
BUN LOP / Store sum
STA SUM / Halt
ADS, HLT / First address of operands
PTR, HEX 150 / Reserved for a pointer
HEX 0 / Initial value for a counter
NBR, DEC -100 / Reserved for a counter
HEX 0 / Sum is stored here
CTR, HEX 0 / Origin of operands is HEX 150
ORG
DEC 75150 / First operand
SUM, .
.
.
DEC 23 / Last operand
END / End of symbolic program
- Software Implementation
- Implementation of an operation with a program
using machine instruction set
- Usually when the operation is not included
in the instruction set
- Hardware Implementation
- Implementation of an operation in a computer
with one machine instruction
X = 0000 1111 P
cir EAC
Y = 0000 1011 0000 0000
Y AC 0000 1111 0000 1111
0001 1110 0010 1101
0000 0000 0010 1101
=0 =1
E 0111 1000 1010 0101
PP+X 1010 0101
E0
AC X
cil EAC
cil
X AC
CTR CTR + 1
0 =0
CTR Stop
ORG 100
LOP, CLE / Clear E
LDA Y / Load multiplier
CIR / Transfer multiplier bit to E
STA Y / Store shifted multiplier
SZE / Check if bit is zero
BUN ONE / Bit is one; goto ONE
BUN ZRO / Bit is zero; goto ZRO
ONE, LDA X / Load multiplicand
ADD P / Add to partial product
STA P / Store partial product
CLE / Clear E
ZRO, LDA X / Load multiplicand
CIL / Shift left
STA X / Store shifted multiplicand
ISZ CTR / Increment counter
BUN LOP / Counter not zero; repeat loop
HLT / Counter is zero; halt
CTR, DEC -8 / This location serves as a counter
X, HEX 000F / Multiplicand stored here
Y, HEX 000B / Multiplier stored here
P, HEX 0 / Product formed here
END
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
102 subroutine
103 STA X / Store shifted
104 number
105 LDA Y / Load Y
106 BSA SH4 / Branch to
107 subroutine again STA Y / Store shifted
108 number
HLT
109 X, HEX 1234
10A Y, HEX 4321
10B / Subroutine to shift left 4
10C times
10D SH4, HEX 0 / Store return address here CIL /
10E Circulate left once
10F CIL CIL
110 CIL / Circulate
left fourth time AND MSK / Set AC(13-
16) to zero BUN SH4 I / Return to
main program
Computer Arch. &MSK,
Org. HEX FFF0 / Mask operand END
Programming the Basic Computer 17 Subroutines
CHARACTER MANIPULATION
PROGRAM INTERRUPT
Tasks of Interrupt Service Routine
- Save the Status of CPU
Contents of processor registers and Flags