Sie sind auf Seite 1von 8

3

str1

?
4

?
1

str2

0
0

0
c

0
5

3
0

info
info
alpha
str1
str2

WORD
RESW
BYTE
RESB
LDA
STA
LDCH
STCH

OPTAB
LDA 00
STA
0c
LDCH 50
STCH 54

32 21 5ch
1
c 'A'
1
info
alpha
str1
str2

alpha

LOCCTR 0000
0001
0002
SYMTAB
info 0000
LABEL OPCODE
OPERAND
0003
alpha 0003
info
WORD
32 21 5ch
0004
str1 0006
alpha RESW
1
0005
str2 0007
str1
BYTE
c 'A'
str2
RESB
1
0006
0007
LDA
info
0008
STA
alpha
LDCH
str1
0009
STCH
str2
000A
000B
Pass 1 assembler must do following
000C
Starting LOCCTR with 0
000D
WORD -----> add 3 to LOCCTR
000E
RESW ------> add 3* # OPERAND to LOCCTR
000F
BYTE -------> add length of constant in bytes
0010
to LOCCTR
0011
0012
RESB --------> add # OPERAND to LOCCTR
0013
OPCODE from OPTAB (i.e instrn) ------> add 3
to LOCCTR to set ready the SYMTAB

info

alpha

str1
str2

Pass 1 assembler must do following


Starting LOCCTR with 0
WORD -----> add 3 to LOCCTR
RESW ------> add 3* # OPERAND to LOCCTR
BYTE -------> add length of constant in bytes
to LOCCTR
RESB --------> add # OPERAND to LOCCTR
OPCODE from OPTAB (i.e instrn) ------> add 3
to LOCCTR

LABEL

OPCODE

OPERAND

info
alpha
info
str2

WORD
RESW
BYTE
RESB

32 21 5ch
1
c 'A'
1

LDA
STA
LDCH
STCH
SYMTAB
info 0000
alpha 0003

info
alpha
str1
str2

If there is a symbol in the LABEL field


Search SYMTAB for LABEL
If found
Set error flag for duplicate symbol
Else
Insert (LABEL LOCCTR) into SYMTAB
Endif
Endif

Search OPTAB for OPCODE


If found add 3 to LOCCTR
Elseif OPCODE = 'WORD'
Add 3 to LOCCTR
Elseif OPCODE = 'RESW'
add 3* # OPERAND to LOCCTR
Elseif OPCODE = 'BYTE'
Add length of constant in bytes to LOCCTR
Elseif OPCODE = 'RESB'
Add # OPERAND to LOCCTR
Else set error flag indicating invalid OPCODE
endif

LABEL

OPCODE

OPERAND

PROG1 START

info
WORD
32 21 5ch
alpha RESW
1
str1
BYTE
c 'A'
str2
RESB
1
. code segment begins here
LDA
info
STA
alpha
LDCH
str1
STCH
str2
END
Intermediate file
0000 info
0003 alpha
0006 str1
0007 str2

WORD
RESW
BYTE
RESB
LDA
STA
LDCH
STCH

Initialize LOCCTR =0
Read input line
While OPCODE != END
If this is not a comment line
If there is a symbol in the LABEL field
Search SYMTAB for LABEL
If found
Set error flag for duplicate symbol
Else
Insert (LABEL LOCCTR) into SYMTAB
Endif
Endif
Search OPTAB for OPCODE
If found add 3 to LOCCTR
Elseif OPCODE = 'WORD'
Add 3 to LOCCTR
Elseif OPCODE = 'RESW'
add 3* # OPERAND to LOCCTR
Elseif OPCODE = 'BYTE'
Add length of constant in bytes to LOCCTR
Elseif OPCODE = 'RESB'
Add # OPERAND to LOCCTR
Else set error flag indicating invalid OPCODE
endif

32 21 5c h
1
c A
1
Endif
info Write line to intermediate file
alpha Read next input line
str1
End While
str2

Intermediate file
Label
0000
0003
0006
0007

info
alpha
str1
str2

opcode
WORD
RESW
BYTE
RESB
LDA
STA
LDCH
STCH

str1

str2

info
operand field
32 21 5c h
1
c A
1
info
alpha
str1
str2

alpha

WORD ==>convert constant to object code


BYTE==>
convert constant to object
code
SYMTAB
directives
info 0000 RESW
alpha 0003 RESB
instructions
str1 0006
str2 0007 OPCODE ==> symbol in the operand
field ?? then store symbol value as operand
address and assemble with opcode
OPTAB
LDA
00 Else
assemble opcode with 0000 as operand
STA
0C
LDCH 50 address
STCH 54
RSUB
4F0000

LABEL

OPCODE

info
alpha
str1
str2

WORD
RESW
BYTE
RESB
LDA
STA
LDCH
STCH

OPTAB
LDA
STA
LDCH
STCH

00
0C
50
54

OPERAND
32 21 5c h
1
c A
1
info
alpha
str1
str2

SYMTAB
info
alpha
str1
str2

0000
0003
0006
0007

WORD ==>convert constant to object code


BYTE ==>convert constant to object code
RESW
RESB
OPCODE ==>symbol in the operand field ??
then store symbol value as operand address
and assemble with opcode
Else
assemble opcode with 0000 as operand
address

Search OPTAB for OPCODE


If found
If there is a symbol in the operand field
search SYMTAB for OPERAND
If found
store symbol value as operand address
else
store 0 as operand address and set error flag
Endif
Else
store 0 as operand address and assemble the object
code
Endif
Else
Convert constant to object code if OPCODE = BYTE or WORD
Endif

T 000000 13 32 21 5c -- -- -- 41 00 00 00 0c 00 03 50 00 06
54 00 07

E 000000

prog1
info
alpha
str1
str2

H prog1

start
WORD
RESW
BYTE
RESB
LDA
STA
LDCH
STCH
End

32 21 5c h
1
c A
1
info
alpha
str1
str2

000000 000013

Header record
Text record
End record

Object program

Write header record to object program


Initailize first text record
Read first input line from intermediate file
While OPCODE !=END
If not comment line
H prog1

000000 000013

T 000000 13 32 21 5c -- -- -- 41
00 00 00 0c 00 03 50 00 06 54 00 07
E 000000

Object program

Search OPTAB for OPCODE


If found
If there is a symbol in the operand field
search SYMTAB for OPERAND
If found
store symbol value as operand address
else
store 0 as operand address and set error flag
Endif
Else
store 0 as operand address and assemble the object code
Endif
Else
Convert constant to object code if OPCODE = BYTE or WORD
Endif
If object code will not fit into the current text record
Write text record into object program
Initialize new text record
End
Add object code to text record

Endif

Endwhile
Write last text record to object program
Write END record to object program

Das könnte Ihnen auch gefallen