0% found this document useful (0 votes)
21 views16 pages

Ch06 - Programming The Basic Computer

This document discusses assembly language and the assembler process. It contains the following key points in 3 sentences: 1) Assembly language programs arrange instructions into three columns - a label field, instruction field, and comment field. Rules define the format of each field. 2) A two pass assembler first generates an address symbol table by scanning the source program, then translates the symbolic program into binary code using the symbol table. 3) The assembler recognizes special pseudoinstructions like ORG and END that provide information, and translates assembly language instructions and addresses into the binary machine language understood by hardware.

Uploaded by

Travel Punjab
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)
21 views16 pages

Ch06 - Programming The Basic Computer

This document discusses assembly language and the assembler process. It contains the following key points in 3 sentences: 1) Assembly language programs arrange instructions into three columns - a label field, instruction field, and comment field. Rules define the format of each field. 2) A two pass assembler first generates an address symbol table by scanning the source program, then translates the symbolic program into binary code using the symbol table. 3) The assembler recognizes special pseudoinstructions like ORG and END that provide information, and translates assembly language instructions and addresses into the binary machine language understood by hardware.

Uploaded by

Travel Punjab
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/ 16

6-1

Chap. 6 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

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-2

„ 6-3 Assembly Language


‹ The rules for writing assembly language program
z Documented and published in manuals(from the computer manufacturer)
Field
‹ Rules of the Assembly Language
z Each line of an assembly language program is arranged in three columns
» 1) Label field : empty or symbolic address
» 2) Instruction field : machine instruction or pseudoinstruction Label Instruction Comment
» 3) Comment field : empty or comment
z Symbolic Address(Label field)
» One, two, or three, but not more than three alphanumeric characters
» The first character must be a letter; the next two may be letters or numerals
» A symbolic address is terminated by a comma(recognized as a label by the assembler)
z Instruction Field
» 1) A memory-reference instruction(MRI)
„ Ex) ADD OPR(direct address MRI), ADD PTR I(indirect address MRI)
» 2) A register-reference or input-output instruction(non-MRI)
„ Ex) CLA(register-reference), INP(input-output)
» 3) A pseudoinstruction with(ORG N) or without(END) an operand : Tab. 6-7
„ Pseudoinstruction 은 Machine Instruction이 아니고 Assembler에게 필요한 정보만 제공

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-3

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

„ 6-4 The Assembler


‹ Source Program Object Code Binary Code
asm
bin
a96 Assembler
Linker exe
a51 (Compiler) obj com
c(cpp)
hex Library 또는 외부 함수를
for
pas 사용하여 Relocation

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-4

‹ Representation of Symbolic Program in Memory : Tab. 6-11


z Line of Code : PL3, LDA SUB I (Carriage return)
» The assembler recognizes a CR code as the end of a line of code
First pass

‹ Two Pass Assembler


LC 0
z 1) 1st pass : Generate user-
defined address symbol table Scan next line of code
Set LC
» Flowchart of first pass :
Fig. 6-1 yes

no no
» Address Symbol Table for Label ORG yes

Program in Tab. 6-8 : yes


yes
Tab. 6-12 END

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

Fig. 6-1 Flowchart for first pass of assembler Increment LC

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-5

Second pass

LC 0

z 2) 2nd pass : Binary translation Scan next line of code


Done

Set LC
» 다음의 4 개의 Table을 참고하여 Yes

Tab. 6-9 에서의 Instruction Format에 의한 Binary Pseudo- Yes No


Yes
END
ORG
Contents를 결정 Code 형성 (Pseudoinstruction Table, instruction
No
MRI Table, Non-MRI Table, Address No
Symbol Table) Yes No
MRI DEC or HEX
» Flowchart of second pass : Convert
이 경우는 Fig. 6-2 Get operation code Valid
operand
No to binary
and set bits 2-4
Hand Assemble non-MRI and store
» Binary Code translation 예제 : instruction in location
given by LC
Yes
Tab. 6-9 의 Content Search address-
symbol table for
» Error Diagnostics binary equivalent
of symbolic address
„ Check for possible errors in the and set bits 5-16 Store binary Error in
Error
equivalent of line of
symbolic program instruction code
Yes No in location
„ Ex) Invalid Machine Code Error I given by LC
Pseudoinstruction,
MRI, non-MRI 에 1 2 3 4 5 6 …. … 15 16 Set first Set first
bit to 1 bit to 0
속하지 않음 I Opcode Address
Assembley all parts of
binary instruction and Increment LC
store in location given by LC

Fig. 6-2 Flowchart for second pass of assembler

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-6

„ 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

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-7

„ 6-6 Programming Arithmetic & Logic Operations


‹ Hardware implementation
z Operations are implemented in a computer with one machine instruction
z Ex) ADD, SUB : 그러나 자리수가 늘어나면 Software subroutine 처리
‹ Software implementation
z Operations are implemented by a set of instruction(Subroutine)
z Ex) MUL, DIV : 그러나 이와 같은 명령어를 갖는 CPU도 있음
‹ Multiplication Program
P=00000000
z Positive Number Multiplication +00001111
X=1111
» X = multiplicand P=00001111
Y=1011
Y = multiplier 1111 +00011110
P = Partial Product Sum 1111 P=00101101
» Y 를 AC 에 저장한 후 E 로 0000
+00000000
1111
Circular Right P=00101101
Algorithm 10100101
„ E = 1 : P에 1111을 더함 +01111000
Fig. 6-3
„ E = 0 : 더하지 않음 P=10100101

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-8

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

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-9

‹ Double Precision Addition : 32 bits


z 하위 AL + BL 먼저 수행하여 Line
E 를 상위에 반영(AH + BH + E) 1 LDA AL / A = AL
2 ADD BL / A = AL + BL
3 STA CL / Store A to CL
31 16 15 0 4 CLA / A=0
5 CIL / 0000 0000 0000 000?(?=E)
AH AL
6 ADD AH / A = 00(E=0) or 01(E=1)
7 ADD BH / A = A + AH + BH
+ BH BL 8 STA CH / Store A to CH
9 HLT
CH CL 10 AL, DEC ? / Operand
11 AH, DEC ?
12 BL, DEC ?
13 BH, DEC ?
14 CL, HEX 0
15 CH, HEX 0
‹ Logic Operations
z Logic Operation 중에서 OR 명령이 없다(Tab. 6-1)
» 추가 하려면 더 길은 Instruction Format 필요 LDA A / Load A
z 해결 방법 : DeMorgan’s theorem CMA / Complement A
STA TMP P / St or
»
A+ B = A+ B = A⋅B LDA B / Load B
CMA / Complement
AND TMP / AND
CMA / Complement

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-10

‹ 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

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-11

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-16 Program to Demonstrate the use of Subroutines

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-12

‹ Subroutine Parameters & Data Linkage


z Parameter(or Argument) Passing Tab. 6-17 Program to Demonstrate Parameter Linkage
» When a subroutine is called, the main Location
ORG 200
program must transfer the data
200 LDA X / Load first operand X
z 2 가지 Parameter Passing 방법 201 BSA OR / Call OR with X
202 HEX 3AF6 / Second operand
» 1) Data transfer through the Accumulator 203 STA Y / Subroutine return here(Y=result)
„ Used for only single input and single 204 HLT
output parameter 205 X, HEX 7B95 / First operand
206 Y, HEX 0 / Result store here
» 2) Data transfer through the Memory 207 OR, HEX 0 / Return address = 202
„ 여러 개의 Operand 전달 가능 208 CMA / Complement X
Call 후에 Return „ Operand are often placed in memory
209 STA TMP / TMP = X
Address를 이용 20A LDA OR I / A = 3AF6 (202 번지의 내용)
locations following the CALL 20B CMA / Complement Second operand
z 2 개의 Parameter Passing 예 : Tab. 6-17 20C AND TMP / AND
20D CMA / 전체 Complement
» First Operand and Result : Accumulator 20E ISZ OR / Return Address = 202 + 1 = 203
20F BUN OR I / Return to main
» Second Operand : Inserted in location
210 TMP, HEX 0
following the BSA END
z BSA후에 2개 Operand 예 : Tab. 6-18
» BSA 후에 2개의 Operand 사용
* OR Subroutine
» Block 전송 Source 와 Destination
First Operand : X = 7B95
Address로 사용
Second Operand : BSA후 = 3AF6

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-13

Tab. 6-18 Subroutine to Move a Block of Data


ORG 100
100 BSA MVE / Subroutine Call
101 HEX 200 / Source Address
102 HEX 300 / Destin Addressa
2 개의
103 DEC -16 / Number of data to move
104 HLT Operand
105 MVE, HEX 0 / Return address= 101
106 LDA MVE I / A= 200
107 STA PT1 / PT1= 200
108 ISZ MVE / Return address= 102
109 LDA MVE I / A= 300
10A STA PT2 / PT2= 300 * Block Move Subroutine
10B ISZ MVE / Return address= 103 메모리 200 번지 부터
10C LDA MVE I / A= -16 16개의 데이터를 메모리
10D STA CTR / CTR= -16
10E ISZ MVE / Return address= 104
300 번지로 이동
10F LOP, LDA PT1 I / A= Address 200의 내용
110 STA PT2 I / Address 300에 저장
111 ISZ PT1 / PT1= 201
112 ISZ PT2 / PT2= 301
113 ISZ CTR / CTR= -15 if 0 skip
114 BUN LOP / Loop until CTR= 0
115 BUN MVE I / 104 로 Retur = HLT
116 PT1, HEX ? / Source
117 PT2, HEX ? / Destination
118 CTR, DEC ? / Counter

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-14

„ 6-8 Input-Output Programming


‹ One-character I/O ‹ Two-character I/O
z Programmed I/O 방식 z Two character Packing

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

1st Char 2nd Char

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-15

‹ Store Input Character in Buffer ‹ Compare Two Word

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

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.
6-16

‹ Interrupt Program Location


ORG 0
0 ZRO, HEX ? / Save Interrupt Return Address
z Interrupt Condition 1 BUN SRV / Jump to ISR
» Interrupt F/F R = 1
ORG 100 / Main program
when IEN = 1 and [FGI or FGO = 1] 100 CLA
101 ION / Turn on Interrupt(IEN= 1)
» Save return address at 0000 Interrupt 102 LDA X
103 ADD Y / Interrupt occurs here
» Jump to 0001 (Interrupt Start) Here 104 STA Z / Return Address(104 )

z Interrupt Service Routine(ISR)


ORG 200
» 1) Save Register (AC, E) 200 SRV, STA SAC / Save A to SAC
» 2) Check Input or Output Flag 201 CIR / Move A into A(15)
202 STA SE / Sav e
» 3) Input or Output Service Routine 203 SKI / Check if FGI= 1?
204 BUN NXT / No, FGI= 0, Check FGO
» 4) Restore Register (AC, E) 205 INP / Yes, FGI= 1, Character Input
206 OUT / Echo back
» 5) Interrupt Enable (ION) 207 STA PT1 I / Store in input buffer(PT1)
» 6) Return to the running program 208 ISZ PT1 / PT1 + 1
NXT, SKO / Check if FGO= 1?
BUN EXT / No, FGO= 0, Exit
LDA PT2 I / Yes, FGO= 1, Get output character
OUT / Character output
ISZ PT2 / PT2 + 1
Modified Fetch Cycle 과 EXT, LDA SE
Reset 시에 IEN = 0 이 된다 CIL / Restore E
(p. 158, Fig. 5-15) LDA SAC / Restore A
ION / Int
e
BUN ZRO I / Return to running program(104 )
SAC, HEX ?
SE, HEX ?
PT1, HEX 300 / Input Buffer Address
PT2, HEX 400 / Output Buffer Address

© Korea Univ. of Tech. & Edu.


Computer System Architecture Chap. 6 Programming the Basic Computer Dept. of Info. & Comm.

You might also like