Ch06 - Programming The Basic Computer
Ch06 - Programming The Basic Computer
6-1 Introduction
Translate user-oriented symbolic program(alphanumeric character set) into
binary programs recognized by the hardware
25 Instruction Set of the basic computer
z Memory Reference Instruction Symbol Hex Code Description
AND 0xxx 8xxx And memory word to AC
z Register Reference Instruction ADD 1xxx 9xxx Add memory word to AC
LDA 2xxx Axxx Load memory word to AC
z Input-output Instruction STA 3xxx Bxxx Store content of AC in memory
BUN 4xxx Cxxx Branch unconditionally
6-2 Machine Language BSA 5xxx Dxxx Branch and Save return address
ISZ 6xxx Exxx Increment and skip if zero
Program Categories CLA 7800 Clear AC
CLE 7400 Clear E
z 1) Binary Code(Machine Language) CMA 7200 Complement AC
CME e 7100 Comp
» Program Memory의 내용 : Tab. 6-2 CIR 7080 Circulate right AC and E
CIL 7040 Circulate left AC and E
z 2) Octal or Hexadecimal Code INC 7020 Increment AC
» Binary Code와 동일 : Tab. 6-3 SPA 7010 Skip next instruction if AC positive
SNA 7008 Skip next instruction if AC negative
z 3) Symbolic Code : Tab. 6-4 SZA 7004 Skip next instruction if AC zero
SZE 7002 Skip next instruction if E is 0
» Assembly Language : Tab. 6-5 HLT 7001 Halt computer
INP F800 Input character to AC
z 4) High Level Language OUT F400 Output character from AC
* Tab. 6-4와 차이점 SKI F200 Skip on input flag
» C, Fortran,.. : Tab 6-6 SKO F100 Skip on output flag
Pseudoinstruction,
ION F080 Interrup
Label 사용 가능 IOF F040 Inter
z Comment field
» Comment filed must be preceded by a slash(recognized by assembler as comment)
An Example Program : Tab. 6-8
z 83 - ( - 23 ) = 83 + ( 2’s Complement of -23)
= 83 + 23 교과서에서는
같은 의미로 사용됨
Translation to Binary : Tab. 6-9
z Assembler = the translation of the symbolic(= assembly) program into binary
z Address Symbol Table = Hexadecimal address of symbolic address
» MIN = 106, SUB = 107, DIF = 108
Two Pass Assembler : in next Sec. 6-4
Ex) LDA SUB
z 1) 1st scan pass : generate user defined address symbol table 1) SUB = 107
z 2) 2nd scan pass : binary translation 2) 2107
no no
» Address Symbol Table for Label ORG yes
no
Store symbol Go to
in address- second
symbol table pass
together with
value of LC
Second pass
LC 0
Set LC
» 다음의 4 개의 Table을 참고하여 Yes
6-5 Program Loops Tab. 6-13 Symbolic Program to Add 100 numbers
Program Loops Line
1 ORG 100
z A sequence of instructions that 2 LDA ADS / A = 150
are executed many times 3 STA PTR / PTR = 150
4 LDA NBR / A = -100
Example of program loop 5 STA CTR / CTR = -100
z Sum of 100 integer numbers 6 CLA / A=0
7 LOP, ADD PTR I / A + 75 (150 번지의 내용)
» Fortran 8 ISZ PTR / 150 + 1 = 151
9 ISZ CTR / -100 + 1 = -99
DIMENSION A(100) 10 BUN LOP / Loop until CTR = 0
INTEGER SUM, A 11 STA SUM / Store A to SUM
SUM = 0 12 HLT
DO 3 J = 1, 100 13 ADS, HEX 150
14 PTR, HEX 0 / 150
3 SUM = SUM + A(J)
15 NBR, DEC -100
16 CTR, HEX 0 / -100
17 SUM, HEX 0 / Result of Sum
z Symbolic Program : Tab 6-13
18 ORG 150
» Address 150 부터 100 개의 19 DEC 75
Data를 더하기 , , , Data
, , .
118 DEC 23
119 END
Fig. 6-3 flowchart for Multiplication Program Tab. 6-14 Program to Multiply Two Positive numbers
Line
CTR -8
P 0 1 ORG 100
2 LOP, CLE /A=0
E 0 3 LDA Y / A = Y (000B)
4 CIR / Circular Right to E
AC Y 5 STA Y / Store shifted Y
6 SZE / Check if E = 0
cir EAC
7 BUN ONE /E=1
Y AC 8 BUN ZRO /E=0
9 ONE, LDA X A = X (000F)
=0 =1 10 ADD P /X=X+P
E
11 STA P / St o r
P P+X 12 CLE / Clear E
13 ZRO, LDA X /A=X
E 0
14 CIL / A = 00011110 (00001111)
15 STA X / St o r
AC X 16 ISZ CTR / CTR = - 7 = -8 + 1
17 BUN LOP / Repeat until CTR = 0
cil EAC
18 HLT
X AC
19 CTR, DEC -8
20 X, HEX 000F
CTR CTR + 1 21 Y, HEX 000B
22 P, HEX 0
≠0 =0
CTR Stop 23 END
Shift Operations
z Logical Shift : Zero must added to the extreme position
» Shift Right CLE E
CIR 0 0
E
» Shift Left CLE
0 0
CIL
z Arithmetic Shift Right
E
» Positive ( + = 0 )
0 0 CLE / E= 0
SPA / Skip if A= +, E= 0
E
» Negative ( - = 1 ) CME / Toggle E(=1) if A= -
1 1 CIR / Circulate A with E
6-7 Subroutines
Subroutine
z A set of common instruction that can be used in a program many times
z In basic computer, the link between the main program and a subroutine is the
BSA instruction(Branch and Save return Address)
z Subroutine example : Tab. 6-16
Location
ORG 100 / Main Program
100 LDA X / Load X
101 BSA SH4 / Call SH4 with X Subroutine
102 STA X / Store result X CALL hear
103 LDA Y / Load Y
104 BSA SH4 / Call SH4 with Y
105 STA Y / Store result Y Ex) 1234
106 HLT - CIL 4 회 = 2340
107 X, HEX 1234 / Result = 2340
- Mask : AND FFF0
108 Y, HEX 4321 / Result = 3210
/ Subr
- 결과 = 2340
109 SH4, HEX 0 / Save Return Address
10A CIL X = 102
10B CIL Y = 105
10C CIL
10D CIL
10E AND MSK / Mask lower 4 bit
10F BUN SH4 I / Indirect Return to main
110 MSK, HEX FFF0 / Mask pattern
110 END
Tab. 6-19 Program to input and output One character Tab. 6-20 Subroutine to input and pack Two character
(a) Input a character IN2, HEX ? / Save return address
CIF, SKI / Check FGI = 1 ? FST, SKI / Check if FGI= 1 ?
BUN CIF / Go to CIF if FGI= 0 BUN FST / Loop (FGI = 0)
INP / Input character (FGI = 1) INP / Input first character
OUT / Echo Back OUT / Echo back
STA CHR / Store character BSA SH4 / Shift left 4 bit
HLT BSA SH4 / Again(total 8 bit shift)
CHR, ? / Store character here SCD, SKI
BUN SCD
(b) Output a character INP / Input second character
LDA CHR / Load output character OUT / Echo back
COF, SKO / Check FGO = 1 ? BUN IN2 I / Return
BUN COF / Go to COF if FGO= 0
OUT / Output character (FGO = 1) 15 8 7 0
HLT 1st Char
CHR, HEX 0057 / Output character = "W"
1st Char
Tab. 6-21 Program to store input character in buffer Tab. 6-22 Program to compare Two word
LDA ADS / Load buffer address A= 500 LDA WD1 / Load first word A= WD1
STA PTR / PTR= 500 CMA / Make 2's complement
LOP, BSA IN2 / Get a character (Tab. 6-20) INC
STA PTR I / 500 번지에 character 저장 ADD WD2 / WD2 - WD1
ISZ PTR / PTR= 501 SZA / Skip if A=0 (Equal)
BUN LOP / Endless Loop BUN UEQ / Unequal
HLT BUN EQL / Equal
ADS, HEX 500 / Buffer address WD1, HEX ? / first word
PTR, HEX 0 / Pointer WD2, HEX ? / second wor