SlideShare a Scribd company logo
1 of 108
Chapter 2
Assemblers
http://www.intel.com/multi-core/demos.htm
Source
Program
Assembler
Object
Code
Executable
Code
Loader
Linker
1
Outline
2
â–  2.1 Basic Assembler Functions
Q A simple SIC assembler
Q Assembler tables and logic
â–  2.2 Machine-Dependent Assembler Features
Q Instruction formats and addressing modes
Q Program relocation
â–  2.3 Machine-Independent Assembler Features
â–  2.4 Assembler Design Options
Q Two-pass
Q One-pass
Q Multi-pass
2.1 Basic Assembler Functions
3
â–  Figure 2.1 shows an assembler language program
for SIC.
Q The line numbers are for reference only.
Q Indexing addressing is indicated by adding the modifier
“,X”
Q Lines beginning with “.” contain comments only.
Q Reads records from input device (code F1)
Q Copies them to output device (code 05)
Q At the end of the file, writes EOF on the output device,
then RSUB to the operating system
4
5
6
2.1 Basic Assembler Functions
7
â–  Assembler directives (pseudo-instructions)
Q START, END, BYTE, WORD, RESB, RESW.
Q These statements are not translated into machine
instructions.
Q Instead, they provide instructions to the assembler
itself.
2.1 Basic Assembler Functions
8
â–  Data transfer (RD, WD)
Q A buffer is used to store record
Q Buffering is necessary for different I/O rates
Q The end of each record is marked with a null character
(0016)
Q Buffer length is 4096 Bytes
Q The end of the file is indicated by a zero-length record
Q When the end of file is detected, the program writes
EOF on the output device and terminates by RSUB.
â–  Subroutines (JSUB, RSUB)
Q RDREC, WRREC
Q Save link (L) register first before nested jump
2.1.1 A simple SIC Assembler
9
â–  Figure 2.2 shows the generated object code for
each statement.
Q Loc gives the machine address in Hex.
Q Assume the program starting at address 1000.
â–  Translation functions
Q Translate STL to 14.
Q Translate RETADR to 1033.
Q Build the machine instructions in the proper format (,X).
Q Translate EOF to 454F46.
Q Write the object program and assembly listing.
10
11
12
2.1.1 A simple SIC Assembler
13
â–  A forward reference
Q 10 1000 FIRST STL RETADR 141033
Q A reference to a label (RETADR) that is defined later in
the program
Q Most assemblers make two passes over the source
program
â–  Most assemblers make two passes over source
program.
Q Pass 1 scans the source for label definitions and
assigns address (Loc).
Q Pass 2 performs most of the actual translation.
2.1.1 A simple SIC Assembler
14
â–  Example of Instruction Assemble
Q Forward reference
Q STCH BUFFER, X
(54)16 1 (001)2 (039)16
8 1 15
m
opcode x address
549039
2.1.1 A simple SIC Assembler
â–  Forward reference
Q Reference to a label that is defined later in the program.
Loc Label OP Code Operand
1000 FIRST STL RETADR
1003 CLOOP JSUB RDREC
…
1012
…
…
…
…
J
…
…
CLOOP
…
1033 RETADR RESW 1
15
2.1.1 A simple SIC Assembler
â–  The object program (OP) will be loaded into
memory for execution.
â–  Three types of records
Q Header: program name, starting address, length.
Q Text: starting address, length, object code.
Q End: address of first executable instruction.
16
2.1.1 A simple SIC Assembler
17
2.1.1 A simple SIC Assembler
â–  The symbol ^ is used to separate fields.
Q Figure 2.3
1E(H)=30(D)=16(D)+14(D)
18
2.1.1 A simple SIC Assembler
19
■ Assembler’s Functions
Q Convert mnemonic operation codes to their machine
language equivalents
â–  STL to 14
Q Convert symbolic operands (referred label) to their
equivalent machine addresses
â–  RETADR to 1033
Q Build the machine instructions in the proper format
Q Convert the data constants to internal machine
representations
Q Write the object program and the assembly listing
20
2.1.1 A simple SIC Assembler
Q Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2).
â–  The functions of the two passes assembler.
â–  Pass 1 (define symbol)
Q Assign addresses to all statements (generate LOC).
Q Check the correctness of Instruction (check with OP table).
Q Save the values (address) assigned to all labels into
SYMBOL table for Pass 2.
Q Perform some processing of assembler directives.
â–  Pass 2
Q Assemble instructions (op code from OP table, address
from SYMBOL table).
Q Generate data values defined by BYTE, WORD.
Q Perform processing of assembler directives not done
during Pass 1.
2.1.2 Assembler Tables and Logic
21
â–  Our simple assembler uses two internal tables: The
OPTAB and SYMTAB.
Q OPTAB is used to look up mnemonic operation codes and
translate them to their machine language equivalents.
■ LDA→00, STL→14, …
Q SYMTAB is used to store values (addresses) assigned to
labels.
■ COPY→1000, FIRST→1000 …
â–  Location Counter LOCCTR
Q LOCCTR is a variable for assignment addresses.
Q LOCCTR is initialized to address specified in START.
Q When reach a label, the current value of LOCCTR gives the
address to be associated with that label.
2.1.2 Assembler Tables and Logic
22
â–  The Operation Code Table (OPTAB)
Q Contain the mnemonic operation & its machine
language equivalents (at least).
Q Contain instruction format & length.
Q Pass 1, OPTAB is used to look up and validate
operation codes.
Q Pass 2, OPTAB is used to translate the operation codes
to machine language.
Q In SIC/XE, assembler search OPTAB in Pass 1 to find
the instruction length for incrementing LOCCTR.
Q Organize as a hash table (static table).
2.1.2 Assembler Tables and Logic
23
â–  The Symbol Table (SYMTAB)
Q Include the name and value (address) for
each label.
Q Include flags to indicate error conditions
Q Contain type, length.
Q Pass 1, labels are entered into SYMTAB,
along with assigned addresses (from
LOCCTR).
Q Pass 2, symbols used as operands are look
up in SYMTAB to obtain the addresses.
Q Organize as a hash table (static table).
Q The entries are rarely deleted from table.
COPY 1000
FIRST 1000
CLOOP 1003
ENDFIL 1015
EOF 1024
THREE 102D
ZERO 1030
RETADR 1033
LENGTH 1036
BUFFER 1039
RDREC 2039
2.1.2 Assembler Tables and Logic
24
â–  Pass 1 usually writes an intermediate file.
Q Contain source statement together with its assigned
address, error indicators.
Q This file is used as input to Pass 2.
â–  Figure 2.4 shows the two passes of
assembler.
â–  Q Format with fields LABEL, OPCODE, and OPERAND.
Q Denote numeric value with the prefix #.
#[OPERAND]
Pass 1
25
26
Pass 2
27
else
if (found symbol==RSUB||
found symbol== …||
found symbol==…)
store 0 as operand address
else
store 0 as operand address
set error flag
assemble the object code inst.
28
2.2 Machine-Dependent Assembler Features
29
â–  Indirect addressing
Q Adding the prefix @ to operand (line 70).
â–  Immediate operands
Q Adding the prefix # to operand (lines 12, 25, 55, 133).
â–  Base relative addressing
Q Assembler directive BASE (lines 12 and 13).
â–  Extended format
Q Adding the prefix + to OP code (lines 15, 35, 65).
â–  The use of register-register instructions.
Q Faster and don’t require another memory reference.
Figure 2.5: First
30
Figure 2.5: RDREC
31
Figure 2.5: WRREC
32
2.2 Machine-Dependent Assembler
33
Features
â–  SIC/XE
Q PC-relative/Base-relative addressing op m
Q Indirect addressing op @m
Q Immediate addressing op #c
Q Extended format +op m
Q Index addressing op m, X
Q register-to-register instructions COMPR
Q larger memory → multi-programming (program
allocation)
2.2 Machine-Dependent Assembler
34
Features
â–  Register translation
Q register name (A, X, L, B, S, T, F, PC, SW) and their values
(0, 1, 2, 3, 4, 5, 6, 8, 9)
Q preloaded in SYMTAB
â–  Address translation
Q Most register-memory instructions use program counter
relative or base relative addressing
Q Format 3: 12-bit disp (address) field
â–  PC-relative: -2048~2047
â–  Base-relative: 0~4095
Q Format 4: 20-bit address field (absolute addressing)
2.2.1 Instruction Formats & Addressing Modes
35
â–  The START statement
Q Specifies a beginning address of 0.
â–  Register-register instructions
Q CLEAR & TIXR, COMPR
â–  Register-memory instructions are using
Q Program-counter (PC) relative addressing
Q The program counter is advanced after each instruction
is fetched and before it is executed.
Q PC will contain the address of the next instruction.
10 0000 FIRST STL RETADR 17202D
TA - (PC) = disp = 30H – 3H= 2D
36
37
38
i=0,
39
+OP, e=1
n=1, i=1,
@m,
#C,
n=1,
n=0,
Extended
Simple
Indirect
Immediate
OPcode+3,
OPcode+2,
i=1, OPcode+1,
2: PC-relative
4: base-relative
8:
1:
xbpe
index (m,X)
extended
2.2.1 Instruction Formats & Addressing
40
Modes
3F2FEC40 0017 J CLOOP
0006 - 001A = disp = -14
Q Base (B), LDB #LENGTH, BASE LENGTH
160 104E STCH BUFFER, X 57C003
55 0020 LDA #3 010003
133 103C +LDT #4096 75101000
TA-(B) = 0036 - (B) = disp = 0036-0033 = 0003
â–  Extended instruction
15 0006 CLOOP +JSUB RDREC 4B101036
â–  Immediate instruction
â–  PC relative + indirect addressing (line 70)
2.2.2 Program Relocation
â–  Absolute program, relocatable program
41
2.2.2 Program Relocation
42
2.2.2 Program Relocation
â–  Modification record (direct addressing)
Q 1 M
Q 2-7 Starting location of the address field to be modified,
relative to the beginning of the program.
Q 8-9 Length of the address field to be modified, in half
bytes.
M^000007^05
43
2.3 Machine-Independent Assembler
44
Features
â–  Write the value of a constant operand as a part of
the instruction that uses it (Fig. 2.9).
â–  A literal is identified with the prefix =
45 001A ENDFIL LDA =C’EOF’ 032010
Q Specifies a 3-byte operand whose value is the character
string EOF.
215 1062 WLOOP TD =X’05’ E32011
Q Specifies a 1-byte literal with the hexadecimal value 05
45
RDREC
46
WRREC
47
2.3.1 Literals
48
LTORG.
â–  The difference between literal operands and
immediate operands
Q =, #
Q Immediate addressing, the operand value is assembled as
part of the machine instruction, no memory reference.
Q With a literal, the assembler generates the specified value
as a constant at some other memory location. The address
of this generated constant is used as the TA for the
machine instruction, using PC-relative or base-relative
addressing with memory reference.
â–  Literal pools
Q At the end of the program (Fig. 2.10).
Q Assembler directive LTORG, it creates a literal pool that
contains all of the literal operands used since the previous
49
RDREC
50
WRREC
51
2.3.1 Literals
52
â–  When to use LTORG (page 69, 4th paragraph)
Q The literal operand would be placed too far away from
the instruction referencing.
Q Cannot use PC-relative addressing or Base-relative
addressing to generate Object Program.
â–  Most assemblers recognize duplicate literals.
Q By comparison of the character strings defining them.
Q =C’EOF’ and =X’454F46’
2.3.1 Literals
53
â–  Allow literals that refer to the current value of the
location counter.
Q Such literals are sometimes useful for loading base
registers.
LDB =*
; register B=beginning address of statement=current LOC
BASE *
; for base relative addressing
â–  If a literal =* appeared on line 13 or 55
Q Specify an operand with value 0003 (Loc) or 0020 (Loc).
2.3.1 Literals
54
â–  Literal table (LITTAB)
Q Contains the literal name (=C’EOF’), the operand value
(454F46) and length (3), and the address (002D).
Q Organized as a hash table.
Q Pass 1, the assembler creates or searches LITTAB for
the specified literal name.
Q Pass 1 encounters a LTORG statement or the end of the
program, the assembler makes a scan of the literal
table.
Q Pass 2, the operand address for use in generating OC is
obtained by searching LITTAB.
2.3.2 Symbol-Defining Statements
â–  Allow the programmer to define symbols and
specify their values.
Q Assembler directive EQU.
Q Improved readability in place of numeric values.
+LDT #4096
MAXLEN EQU
+LDT
BUFEND-BUFFER
#MAXLEN
(4096)
â–  Use EQU in defining mnemonic names for registers.
Q Registers A, X, L can be used by numbers 0, 1, 2.
RMO 0, 1
RMO A, X
55
2.3.2 Symbol-Defining Statements
56
â–  The standard names reflect the usage of the
registers.
BASE EQU R1
COUNT EQU R2
INDEX EQU R3
â–  Assembler directive ORG
Q Use to indirectly assign values to symbols.
ORG value
Q The assembler resets its LOCCTR to the specified value.
Q ORG can be useful in label definition.
5
2.3.2 Symbol-Defining Statements
â–  The location counter is used to control assignment
of storage in the object program
Q In most cases, altering its value would result in an
incorrect assembly.
â–  ORG is used
http://home.educities.edu.tw/wanker742126/index.html
Q SYMBOL is 6-byte, VALUE is 3-byte, and FLAGS is 2-byte.
7
2.3.2 Symbol-Defining Statements
58
STAB SYMBOL VALUE FLAGS
(100 entries) 6 3 2
LOC
1000 STAB RESB 1100
1000 SYMBOL EQU STAB +0
1006 VALUE EQU STAB +6
1009 FLAGS EQU STAB +9
â–  Use LDA VALUE, X to fetch the VALUE field form the
table entry indicated by the contents of register X.
2.3.2 Symbol-Defining Statements
STAB SYMBOL VALUE FLAGS
(100 entries) 6 3 2
1000 STAB RESB 1100
ORG STAB
1000 SYMBOL RESB 6
1006 VALUE RESW 1
1009 FLAGS RESB 2
ORG STAB+1100
59
2.3.2 Symbol-Defining Statements
60
â–  All terms used to specify the value of the new
symbol --- must have been defined previously in
the program.
...
EQU ALPHA
RESW 1
BETA
ALPHA
...
Need 2 passes
61
2.3.2 Symbol-Defining Statements
Need 3 passes
â–  All symbols used to specify new location counter
value must have been previously defined.
ORG ALPHA
BYTE1 RESB 1
BYTE2 RESB 1
BYTE3 RESB 1
ORG
ALPHA RESW 1
â–  Forward reference
ALPHA EQU BETA
BETA EQU DELTA
DELTA RESW 1
2.3.3 Expressions
62
â–  Allow arithmetic expressions formed
Q Using the operators +, -, ď‚´, /.
Q Division is usually defined to produce an integer result.
Q Expression may be constants, user-defined symbols, or
special terms.
106 1036 BUFEND EQU *
Q Gives BUFEND a value that is the address of the next
byte after the buffer area.
â–  Absolute expressions or relative expressions
Q A relative term or expression represents some value
(S+r), S: starting address, r: the relative value.
2.3.3 Expressions
107 1000 MAXLEN EQU BUFEND-BUFFER
Q Both BUFEND and BUFFER are relative terms.
Q The expression represents absolute value: the difference
between the two addresses.
Q Loc =1000 (Hex)
Q The value that is associated with the symbol that
appears in the source statement.
Q BUFEND+BUFFER, 100-BUFFER, 3*BUFFER represent
neither absolute values nor locations.
â–  Symbol tables entries
63
2.3.4 Program Blocks
64
â–  The source program logically contained main,
subroutines, data areas.
Q In a single block of object code.
â–  More flexible (Different blocks)
Q Generate machine instructions (codes) and data in a
different order from the corresponding source statements.
â–  Program blocks
Q Refer to segments of code that are rearranged within a
single object program unit.
â–  Control sections
Q Refer to segments of code that are translated into
independent object program units.
2.3.4 Program Blocks
65
â–  Three blocks, Figure 2.11
Q Default (USE), CDATA (USE CDATA), CBLKS (USE CBLKS).
â–  Assembler directive USE
Q Indicates which portions of the source program blocks.
Q At the beginning of the program, statements are
assumed to be part of the default block.
Q Lines 92, 103, 123, 183, 208, 252.
â–  Each program block may contain several separate
segments.
Q The assembler will rearrange these segments to gather
together the pieces of each block.
Main
66
RDREC
67
WRREC
68
2.3.4 Program Blocks
69
â–  Pass 1, Figure 2.12
Q The block number is started form 0.
Q A separate location counter for each program block.
Q The location counter for a block is initialized to 0 when
the block is first begun.
Q Assign each block a starting address in the object
program (location 0).
Q Labels, block name or block number, relative addr.
Q Working table is generated
Block name Block number Address End Length
default 0 0000 0065 0066 (0~0065)
CDATA 1 0066 0070 000B (0~000A)
CBLKS 2 0071 1070 1000 (0~0FFF)
70
71
72
2.3.4 Program Blocks
73
â–  Pass 2, Figure 2.12
Q The assembler needs the address for each symbol
relative to the start of the object program.
Q Loc shows the relative address and block number.
Q Notice that the value of the symbol MAXLEN (line 70) is
shown without a block number.
20 0006 0 LDA LENGTH 032060
0003(CDATA) +0066 =0069 =TA
using program-counter relative addressing
TA - (PC) =0069-0009 =0060 =disp
2.3.4 Program Blocks
74
â–  Separation of the program into blocks.
Q Because the large buffer (CBLKS) is moved to the end of
the object program.
Q No longer need extended format, base register, simply a
LTORG statement.
Q No need Modification records.
Q Improve program readability.
â–  Figure 2.13
Q Reflect the starting address of the block as well as the
relative location of the code within the block.
â–  Figure 2.14
Q Loader simply loads the object code from each record at
the dictated.
Q CDATA(1) & CBLKS(1) are not actually present in OP.
2.3.4 Program Blocks
Default 1
Default 2
CDATA 2
Default 3
CDATA 3
75
76
2.3.5 Control Sections & Program Linking
77
â–  Control section
Q Handling of programs that consist of multiple control
sections.
Q Each control section is a part of the program.
Q Can be assembled, loaded and relocated independently.
Q Different control sections are most often used for
subroutines or other logical subdivisions of a program.
Q The programmer can assemble, load, and manipulate
each of these control sections separately.
Q More Flexibility then the previous.
Q Linking control sections together.
2.3.5 Control Sections & Program Linking
78
â–  External references (external symbol references)
Q Instructions in one control section might need to refer to
instructions or data located in another section.
â–  Figure 2.15, multiple control sections.
Q Three sections, main COPY, RDREC, WRREC.
Q Assembler directive CSECT.
Q Assembler directives EXTDEF and EXTREF for external
symbols.
Q The order of symbols is not significant.
COPY START 0
EXTDEF BUFFER, BUFEND, LENGTH
EXTREF RDREC, WRREC (symbol name)
79
80
81
2.3.5 Control Sections & Program Linking
82
â–  Figure 2.16, the generated object code.
15
160
0003
0017
CLOOP +JSUB RDREC
+STCH BUFFER,X
4B100000
57900000
Q The LOC of all control section is started form 0
Q RDREC is an external reference.
Q The assembler has no idea where the control section
containing RDREC will be loaded, so it cannot assemble
the address.
Q The proper address to be inserted at load time.
Q Must use extended format instruction for external
reference (M records are needed).
190 0028 MAXLEN WORD BUFEND-BUFFER
Q An expression involving two external references.
83
84
85
2.3.5 Control Sections & Program Linking
86
Q The loader will add to this data area with the address of
BUFEND and subtract from it the address of BUFFER.
(COPY and RDREC for MAXLEN)
Q Line 190 and 107, in 107, the symbols BUFEND and
BUFFER are defined in the same section.
Q The assembler must remember in which control section
a symbol is defined.
Q The assembler allows the same symbol to be used in
different control sections, lines 107 and 190.
â–  Figure 2.17, two new records.
Q Defined record for EXTDEF, relative address.
Q Refer record for EXTREF.
87
2.3.5 Control Sections & Program Linking
â–  Modification record
Q M
Q Starting address of the field to be modified, relative to
the beginning of the control section (Hex).
Q Length of the field to be modified, in half-bytes.
Q Modification flag (+ or -).
Q External symbol.
M^000004^05+RDREC
M^000028^06+BUFEND
M^000028^06-BUFFER
â–  Use Figure 2.8 for program relocation.
88
89
90
2.4 Assembler Design Options
91
2.4.1 Two-Pass Assembler
â–  Most assemblers
Q Processing the source program into two passes.
Q The internal tables and subroutines that are used only
during Pass 1.
Q The SYMTAB, LITTAB, and OPTAB are used by both
passes.
â–  The main problems to assemble a program in one
pass involves forward references.
2.4.2 One-Pass Assemblers
92
â–  Eliminate forward references
Q Data items are defined before they are referenced.
Q But, forward references to labels on instructions cannot
be eliminated as easily.
Q Prohibit forward references to labels.
â–  Two types of one-pass assembler. (Fig. 2.18)
Q One type produces object code directly in memory for
immediate execution.
Q The other type produces the usual kind of object
program for later execution.
94
95
2.4.2 One-Pass Assemblers
96
â–  Load-and-go one-pass assembler
Q The assembler avoids the overhead of writing the object
program out and reading it back in.
Q The object program is produced in memory, the
handling of forward references becomes less difficult.
Q Figure 2.19(a), shows the SYMTAB after scanning line
40 of the program in Figure 2.18.
Q Since RDREC was not yet defined, the instruction was
assembled with no value assigned as the operand
address (denote by - - - -).
97
98
2.4.2 One-Pass Assemblers
99
â–  Load-and-go one-pass assembler
Q RDREC was then entered into SYMTAB as an undefined
symbol, the address of the operand field of the
instruction (2013) was inserted.
Q Figure 2.19(b), when the symbol ENDFIL was defined
(line 45), the assembler placed its value in the SYMTAB
entry; it then inserted this value into the instruction
operand field (201C).
Q At the end of the program, all symbols must be defined
without any * in SYMTAB.
Q For a load-and-go assembler, the actual address must
be known at assembly time.
2.4.2 One-Pass Assemblers
100
â–  Another one-pass assembler by generating OP
Q Generate another Text record with correct operand address.
Q When the program is loaded, this address will be inserted
into the instruction by the action of the loader.
Q Figure 2.20, the operand addresses for the instructions on
lines 15, 30, and 35 have been generated as 0000.
Q When the definition of ENDFIL is encountered on line 45,
the third Text record is generated, the value 2024 is to be
loaded at location 201C.
Q The loader completes forward references.
ENDFIL
RDREC
EXIT
WRREC
101
2.4.2 One-Pass Assemblers
102
â–  In this section, simple one-pass assemblers
handled absolute programs (SIC example).
2.4.3 Multi-Pass Assemblers
â–  Use EQU, any symbol used on the RHS be defined previously
in the source.
LOC Pass1 2 3
1000 LDA #0 1000 1000 1000
1003 ALPHA EQU BETA ???? ???? 1003
1003 BETA EQU DELTA ???? 1003 1003
1003 DELTA RESW 1 1003 1003 1003
Q Need 3 passes!
â–  Figure 2.21, multi-pass assembler
103
2.4.3 Multi-Pass Assemblers
104
2.4.3 Multi-Pass Assemblers
105
2.4.3 Multi-Pass Assemblers
106
2.4.3 Multi-Pass Assemblers
107
2.4.3 Multi-Pass Assemblers
108

More Related Content

What's hot

Lecture Notes-Are Natural Languages Regular.pdf
Lecture Notes-Are Natural Languages Regular.pdfLecture Notes-Are Natural Languages Regular.pdf
Lecture Notes-Are Natural Languages Regular.pdfDeptii Chaudhari
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)Vaibhav Bajaj
 
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transferlavanya marichamy
 
Macro Processor
Macro ProcessorMacro Processor
Macro ProcessorSaranya1702
 
System programming vs application programming
System programming vs application programmingSystem programming vs application programming
System programming vs application programmingInderbir Kaur Sandhu
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler DesignMuhammed Afsal Villan
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysisSoujanya V
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal languageRabia Khalid
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic NotationProtap Mondal
 
Computer instructions
Computer instructionsComputer instructions
Computer instructionsAnuj Modi
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Lecture 3 instruction set
Lecture 3  instruction setLecture 3  instruction set
Lecture 3 instruction setPradeep Kumar TS
 
Micro programmed control
Micro programmed controlMicro programmed control
Micro programmed controlSyed Zaid Irshad
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInteX Research Lab
 

What's hot (20)

Lecture Notes-Are Natural Languages Regular.pdf
Lecture Notes-Are Natural Languages Regular.pdfLecture Notes-Are Natural Languages Regular.pdf
Lecture Notes-Are Natural Languages Regular.pdf
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 
Register Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory TransferRegister Transfer Language,Bus and Memory Transfer
Register Transfer Language,Bus and Memory Transfer
 
Macro Processor
Macro ProcessorMacro Processor
Macro Processor
 
Instruction cycle
Instruction cycleInstruction cycle
Instruction cycle
 
System programming vs application programming
System programming vs application programmingSystem programming vs application programming
System programming vs application programming
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Instruction codes
Instruction codesInstruction codes
Instruction codes
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Assembler
AssemblerAssembler
Assembler
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Computer instructions
Computer instructionsComputer instructions
Computer instructions
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Lecture 3 instruction set
Lecture 3  instruction setLecture 3  instruction set
Lecture 3 instruction set
 
Micro programmed control
Micro programmed controlMicro programmed control
Micro programmed control
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer Architecture
 

Similar to Sp chap2

assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.pptAshwini864432
 
Assembler
AssemblerAssembler
AssemblerMir Majid
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler ProgrammingOmar Sanchez
 
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed controlB.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed controlRai University
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlBca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlRai University
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set ArchitectureDilum Bandara
 
Computer Organization
Computer Organization Computer Organization
Computer Organization Radhika Talaviya
 
heuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptxheuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptxchristinamary2620
 
basic computer programming and micro programmed control
basic computer programming and micro programmed controlbasic computer programming and micro programmed control
basic computer programming and micro programmed controlRai University
 
Mca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed controlMca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed controlRai University
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programmingMakerere university
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction setKarthik Vivek
 

Similar to Sp chap2 (20)

assembler_full_slides.ppt
assembler_full_slides.pptassembler_full_slides.ppt
assembler_full_slides.ppt
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
System Software
System SoftwareSystem Software
System Software
 
Assembler
AssemblerAssembler
Assembler
 
Assembler
AssemblerAssembler
Assembler
 
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
 
Assembler (2)
Assembler (2)Assembler (2)
Assembler (2)
 
Assembler
AssemblerAssembler
Assembler
 
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed controlB.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlBca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
 
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
 
Computer Organization
Computer Organization Computer Organization
Computer Organization
 
Assembler1
Assembler1Assembler1
Assembler1
 
heuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptxheuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptx
 
basic computer programming and micro programmed control
basic computer programming and micro programmed controlbasic computer programming and micro programmed control
basic computer programming and micro programmed control
 
Mca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed controlMca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed control
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programming
 
ARM instruction set
ARM instruction  setARM instruction  set
ARM instruction set
 

Recently uploaded

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

Sp chap2

  • 2. Outline 2 â–  2.1 Basic Assembler Functions Q A simple SIC assembler Q Assembler tables and logic â–  2.2 Machine-Dependent Assembler Features Q Instruction formats and addressing modes Q Program relocation â–  2.3 Machine-Independent Assembler Features â–  2.4 Assembler Design Options Q Two-pass Q One-pass Q Multi-pass
  • 3. 2.1 Basic Assembler Functions 3 â–  Figure 2.1 shows an assembler language program for SIC. Q The line numbers are for reference only. Q Indexing addressing is indicated by adding the modifier “,X” Q Lines beginning with “.” contain comments only. Q Reads records from input device (code F1) Q Copies them to output device (code 05) Q At the end of the file, writes EOF on the output device, then RSUB to the operating system
  • 4. 4
  • 5. 5
  • 6. 6
  • 7. 2.1 Basic Assembler Functions 7 â–  Assembler directives (pseudo-instructions) Q START, END, BYTE, WORD, RESB, RESW. Q These statements are not translated into machine instructions. Q Instead, they provide instructions to the assembler itself.
  • 8. 2.1 Basic Assembler Functions 8 â–  Data transfer (RD, WD) Q A buffer is used to store record Q Buffering is necessary for different I/O rates Q The end of each record is marked with a null character (0016) Q Buffer length is 4096 Bytes Q The end of the file is indicated by a zero-length record Q When the end of file is detected, the program writes EOF on the output device and terminates by RSUB. â–  Subroutines (JSUB, RSUB) Q RDREC, WRREC Q Save link (L) register first before nested jump
  • 9. 2.1.1 A simple SIC Assembler 9 â–  Figure 2.2 shows the generated object code for each statement. Q Loc gives the machine address in Hex. Q Assume the program starting at address 1000. â–  Translation functions Q Translate STL to 14. Q Translate RETADR to 1033. Q Build the machine instructions in the proper format (,X). Q Translate EOF to 454F46. Q Write the object program and assembly listing.
  • 10. 10
  • 11. 11
  • 12. 12
  • 13. 2.1.1 A simple SIC Assembler 13 â–  A forward reference Q 10 1000 FIRST STL RETADR 141033 Q A reference to a label (RETADR) that is defined later in the program Q Most assemblers make two passes over the source program â–  Most assemblers make two passes over source program. Q Pass 1 scans the source for label definitions and assigns address (Loc). Q Pass 2 performs most of the actual translation.
  • 14. 2.1.1 A simple SIC Assembler 14 â–  Example of Instruction Assemble Q Forward reference Q STCH BUFFER, X (54)16 1 (001)2 (039)16 8 1 15 m opcode x address 549039
  • 15. 2.1.1 A simple SIC Assembler â–  Forward reference Q Reference to a label that is defined later in the program. Loc Label OP Code Operand 1000 FIRST STL RETADR 1003 CLOOP JSUB RDREC … 1012 … … … … J … … CLOOP … 1033 RETADR RESW 1 15
  • 16. 2.1.1 A simple SIC Assembler â–  The object program (OP) will be loaded into memory for execution. â–  Three types of records Q Header: program name, starting address, length. Q Text: starting address, length, object code. Q End: address of first executable instruction. 16
  • 17. 2.1.1 A simple SIC Assembler 17
  • 18. 2.1.1 A simple SIC Assembler â–  The symbol ^ is used to separate fields. Q Figure 2.3 1E(H)=30(D)=16(D)+14(D) 18
  • 19. 2.1.1 A simple SIC Assembler 19 â–  Assembler’s Functions Q Convert mnemonic operation codes to their machine language equivalents â–  STL to 14 Q Convert symbolic operands (referred label) to their equivalent machine addresses â–  RETADR to 1033 Q Build the machine instructions in the proper format Q Convert the data constants to internal machine representations Q Write the object program and the assembly listing
  • 20. 20 2.1.1 A simple SIC Assembler Q Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2). â–  The functions of the two passes assembler. â–  Pass 1 (define symbol) Q Assign addresses to all statements (generate LOC). Q Check the correctness of Instruction (check with OP table). Q Save the values (address) assigned to all labels into SYMBOL table for Pass 2. Q Perform some processing of assembler directives. â–  Pass 2 Q Assemble instructions (op code from OP table, address from SYMBOL table). Q Generate data values defined by BYTE, WORD. Q Perform processing of assembler directives not done during Pass 1.
  • 21. 2.1.2 Assembler Tables and Logic 21 â–  Our simple assembler uses two internal tables: The OPTAB and SYMTAB. Q OPTAB is used to look up mnemonic operation codes and translate them to their machine language equivalents. â–  LDA→00, STL→14, … Q SYMTAB is used to store values (addresses) assigned to labels. â–  COPY→1000, FIRST→1000 … â–  Location Counter LOCCTR Q LOCCTR is a variable for assignment addresses. Q LOCCTR is initialized to address specified in START. Q When reach a label, the current value of LOCCTR gives the address to be associated with that label.
  • 22. 2.1.2 Assembler Tables and Logic 22 â–  The Operation Code Table (OPTAB) Q Contain the mnemonic operation & its machine language equivalents (at least). Q Contain instruction format & length. Q Pass 1, OPTAB is used to look up and validate operation codes. Q Pass 2, OPTAB is used to translate the operation codes to machine language. Q In SIC/XE, assembler search OPTAB in Pass 1 to find the instruction length for incrementing LOCCTR. Q Organize as a hash table (static table).
  • 23. 2.1.2 Assembler Tables and Logic 23 â–  The Symbol Table (SYMTAB) Q Include the name and value (address) for each label. Q Include flags to indicate error conditions Q Contain type, length. Q Pass 1, labels are entered into SYMTAB, along with assigned addresses (from LOCCTR). Q Pass 2, symbols used as operands are look up in SYMTAB to obtain the addresses. Q Organize as a hash table (static table). Q The entries are rarely deleted from table. COPY 1000 FIRST 1000 CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039
  • 24. 2.1.2 Assembler Tables and Logic 24 â–  Pass 1 usually writes an intermediate file. Q Contain source statement together with its assigned address, error indicators. Q This file is used as input to Pass 2. â–  Figure 2.4 shows the two passes of assembler. â–  Q Format with fields LABEL, OPCODE, and OPERAND. Q Denote numeric value with the prefix #. #[OPERAND]
  • 26. 26
  • 28. else if (found symbol==RSUB|| found symbol== …|| found symbol==…) store 0 as operand address else store 0 as operand address set error flag assemble the object code inst. 28
  • 29. 2.2 Machine-Dependent Assembler Features 29 â–  Indirect addressing Q Adding the prefix @ to operand (line 70). â–  Immediate operands Q Adding the prefix # to operand (lines 12, 25, 55, 133). â–  Base relative addressing Q Assembler directive BASE (lines 12 and 13). â–  Extended format Q Adding the prefix + to OP code (lines 15, 35, 65). â–  The use of register-register instructions. Q Faster and don’t require another memory reference.
  • 33. 2.2 Machine-Dependent Assembler 33 Features â–  SIC/XE Q PC-relative/Base-relative addressing op m Q Indirect addressing op @m Q Immediate addressing op #c Q Extended format +op m Q Index addressing op m, X Q register-to-register instructions COMPR Q larger memory → multi-programming (program allocation)
  • 34. 2.2 Machine-Dependent Assembler 34 Features â–  Register translation Q register name (A, X, L, B, S, T, F, PC, SW) and their values (0, 1, 2, 3, 4, 5, 6, 8, 9) Q preloaded in SYMTAB â–  Address translation Q Most register-memory instructions use program counter relative or base relative addressing Q Format 3: 12-bit disp (address) field â–  PC-relative: -2048~2047 â–  Base-relative: 0~4095 Q Format 4: 20-bit address field (absolute addressing)
  • 35. 2.2.1 Instruction Formats & Addressing Modes 35 â–  The START statement Q Specifies a beginning address of 0. â–  Register-register instructions Q CLEAR & TIXR, COMPR â–  Register-memory instructions are using Q Program-counter (PC) relative addressing Q The program counter is advanced after each instruction is fetched and before it is executed. Q PC will contain the address of the next instruction. 10 0000 FIRST STL RETADR 17202D TA - (PC) = disp = 30H – 3H= 2D
  • 36. 36
  • 37. 37
  • 38. 38
  • 39. i=0, 39 +OP, e=1 n=1, i=1, @m, #C, n=1, n=0, Extended Simple Indirect Immediate OPcode+3, OPcode+2, i=1, OPcode+1, 2: PC-relative 4: base-relative 8: 1: xbpe index (m,X) extended
  • 40. 2.2.1 Instruction Formats & Addressing 40 Modes 3F2FEC40 0017 J CLOOP 0006 - 001A = disp = -14 Q Base (B), LDB #LENGTH, BASE LENGTH 160 104E STCH BUFFER, X 57C003 55 0020 LDA #3 010003 133 103C +LDT #4096 75101000 TA-(B) = 0036 - (B) = disp = 0036-0033 = 0003 â–  Extended instruction 15 0006 CLOOP +JSUB RDREC 4B101036 â–  Immediate instruction â–  PC relative + indirect addressing (line 70)
  • 41. 2.2.2 Program Relocation â–  Absolute program, relocatable program 41
  • 43. 2.2.2 Program Relocation â–  Modification record (direct addressing) Q 1 M Q 2-7 Starting location of the address field to be modified, relative to the beginning of the program. Q 8-9 Length of the address field to be modified, in half bytes. M^000007^05 43
  • 44. 2.3 Machine-Independent Assembler 44 Features â–  Write the value of a constant operand as a part of the instruction that uses it (Fig. 2.9). â–  A literal is identified with the prefix = 45 001A ENDFIL LDA =C’EOF’ 032010 Q Specifies a 3-byte operand whose value is the character string EOF. 215 1062 WLOOP TD =X’05’ E32011 Q Specifies a 1-byte literal with the hexadecimal value 05
  • 45. 45
  • 48. 2.3.1 Literals 48 LTORG. â–  The difference between literal operands and immediate operands Q =, # Q Immediate addressing, the operand value is assembled as part of the machine instruction, no memory reference. Q With a literal, the assembler generates the specified value as a constant at some other memory location. The address of this generated constant is used as the TA for the machine instruction, using PC-relative or base-relative addressing with memory reference. â–  Literal pools Q At the end of the program (Fig. 2.10). Q Assembler directive LTORG, it creates a literal pool that contains all of the literal operands used since the previous
  • 49. 49
  • 52. 2.3.1 Literals 52 â–  When to use LTORG (page 69, 4th paragraph) Q The literal operand would be placed too far away from the instruction referencing. Q Cannot use PC-relative addressing or Base-relative addressing to generate Object Program. â–  Most assemblers recognize duplicate literals. Q By comparison of the character strings defining them. Q =C’EOF’ and =X’454F46’
  • 53. 2.3.1 Literals 53 â–  Allow literals that refer to the current value of the location counter. Q Such literals are sometimes useful for loading base registers. LDB =* ; register B=beginning address of statement=current LOC BASE * ; for base relative addressing â–  If a literal =* appeared on line 13 or 55 Q Specify an operand with value 0003 (Loc) or 0020 (Loc).
  • 54. 2.3.1 Literals 54 â–  Literal table (LITTAB) Q Contains the literal name (=C’EOF’), the operand value (454F46) and length (3), and the address (002D). Q Organized as a hash table. Q Pass 1, the assembler creates or searches LITTAB for the specified literal name. Q Pass 1 encounters a LTORG statement or the end of the program, the assembler makes a scan of the literal table. Q Pass 2, the operand address for use in generating OC is obtained by searching LITTAB.
  • 55. 2.3.2 Symbol-Defining Statements â–  Allow the programmer to define symbols and specify their values. Q Assembler directive EQU. Q Improved readability in place of numeric values. +LDT #4096 MAXLEN EQU +LDT BUFEND-BUFFER #MAXLEN (4096) â–  Use EQU in defining mnemonic names for registers. Q Registers A, X, L can be used by numbers 0, 1, 2. RMO 0, 1 RMO A, X 55
  • 56. 2.3.2 Symbol-Defining Statements 56 â–  The standard names reflect the usage of the registers. BASE EQU R1 COUNT EQU R2 INDEX EQU R3 â–  Assembler directive ORG Q Use to indirectly assign values to symbols. ORG value Q The assembler resets its LOCCTR to the specified value. Q ORG can be useful in label definition.
  • 57. 5 2.3.2 Symbol-Defining Statements â–  The location counter is used to control assignment of storage in the object program Q In most cases, altering its value would result in an incorrect assembly. â–  ORG is used http://home.educities.edu.tw/wanker742126/index.html Q SYMBOL is 6-byte, VALUE is 3-byte, and FLAGS is 2-byte. 7
  • 58. 2.3.2 Symbol-Defining Statements 58 STAB SYMBOL VALUE FLAGS (100 entries) 6 3 2 LOC 1000 STAB RESB 1100 1000 SYMBOL EQU STAB +0 1006 VALUE EQU STAB +6 1009 FLAGS EQU STAB +9 â–  Use LDA VALUE, X to fetch the VALUE field form the table entry indicated by the contents of register X.
  • 59. 2.3.2 Symbol-Defining Statements STAB SYMBOL VALUE FLAGS (100 entries) 6 3 2 1000 STAB RESB 1100 ORG STAB 1000 SYMBOL RESB 6 1006 VALUE RESW 1 1009 FLAGS RESB 2 ORG STAB+1100 59
  • 60. 2.3.2 Symbol-Defining Statements 60 â–  All terms used to specify the value of the new symbol --- must have been defined previously in the program. ... EQU ALPHA RESW 1 BETA ALPHA ... Need 2 passes
  • 61. 61 2.3.2 Symbol-Defining Statements Need 3 passes â–  All symbols used to specify new location counter value must have been previously defined. ORG ALPHA BYTE1 RESB 1 BYTE2 RESB 1 BYTE3 RESB 1 ORG ALPHA RESW 1 â–  Forward reference ALPHA EQU BETA BETA EQU DELTA DELTA RESW 1
  • 62. 2.3.3 Expressions 62 â–  Allow arithmetic expressions formed Q Using the operators +, -, ď‚´, /. Q Division is usually defined to produce an integer result. Q Expression may be constants, user-defined symbols, or special terms. 106 1036 BUFEND EQU * Q Gives BUFEND a value that is the address of the next byte after the buffer area. â–  Absolute expressions or relative expressions Q A relative term or expression represents some value (S+r), S: starting address, r: the relative value.
  • 63. 2.3.3 Expressions 107 1000 MAXLEN EQU BUFEND-BUFFER Q Both BUFEND and BUFFER are relative terms. Q The expression represents absolute value: the difference between the two addresses. Q Loc =1000 (Hex) Q The value that is associated with the symbol that appears in the source statement. Q BUFEND+BUFFER, 100-BUFFER, 3*BUFFER represent neither absolute values nor locations. â–  Symbol tables entries 63
  • 64. 2.3.4 Program Blocks 64 â–  The source program logically contained main, subroutines, data areas. Q In a single block of object code. â–  More flexible (Different blocks) Q Generate machine instructions (codes) and data in a different order from the corresponding source statements. â–  Program blocks Q Refer to segments of code that are rearranged within a single object program unit. â–  Control sections Q Refer to segments of code that are translated into independent object program units.
  • 65. 2.3.4 Program Blocks 65 â–  Three blocks, Figure 2.11 Q Default (USE), CDATA (USE CDATA), CBLKS (USE CBLKS). â–  Assembler directive USE Q Indicates which portions of the source program blocks. Q At the beginning of the program, statements are assumed to be part of the default block. Q Lines 92, 103, 123, 183, 208, 252. â–  Each program block may contain several separate segments. Q The assembler will rearrange these segments to gather together the pieces of each block.
  • 69. 2.3.4 Program Blocks 69 â–  Pass 1, Figure 2.12 Q The block number is started form 0. Q A separate location counter for each program block. Q The location counter for a block is initialized to 0 when the block is first begun. Q Assign each block a starting address in the object program (location 0). Q Labels, block name or block number, relative addr. Q Working table is generated Block name Block number Address End Length default 0 0000 0065 0066 (0~0065) CDATA 1 0066 0070 000B (0~000A) CBLKS 2 0071 1070 1000 (0~0FFF)
  • 70. 70
  • 71. 71
  • 72. 72
  • 73. 2.3.4 Program Blocks 73 â–  Pass 2, Figure 2.12 Q The assembler needs the address for each symbol relative to the start of the object program. Q Loc shows the relative address and block number. Q Notice that the value of the symbol MAXLEN (line 70) is shown without a block number. 20 0006 0 LDA LENGTH 032060 0003(CDATA) +0066 =0069 =TA using program-counter relative addressing TA - (PC) =0069-0009 =0060 =disp
  • 74. 2.3.4 Program Blocks 74 â–  Separation of the program into blocks. Q Because the large buffer (CBLKS) is moved to the end of the object program. Q No longer need extended format, base register, simply a LTORG statement. Q No need Modification records. Q Improve program readability. â–  Figure 2.13 Q Reflect the starting address of the block as well as the relative location of the code within the block. â–  Figure 2.14 Q Loader simply loads the object code from each record at the dictated. Q CDATA(1) & CBLKS(1) are not actually present in OP.
  • 75. 2.3.4 Program Blocks Default 1 Default 2 CDATA 2 Default 3 CDATA 3 75
  • 76. 76
  • 77. 2.3.5 Control Sections & Program Linking 77 â–  Control section Q Handling of programs that consist of multiple control sections. Q Each control section is a part of the program. Q Can be assembled, loaded and relocated independently. Q Different control sections are most often used for subroutines or other logical subdivisions of a program. Q The programmer can assemble, load, and manipulate each of these control sections separately. Q More Flexibility then the previous. Q Linking control sections together.
  • 78. 2.3.5 Control Sections & Program Linking 78 â–  External references (external symbol references) Q Instructions in one control section might need to refer to instructions or data located in another section. â–  Figure 2.15, multiple control sections. Q Three sections, main COPY, RDREC, WRREC. Q Assembler directive CSECT. Q Assembler directives EXTDEF and EXTREF for external symbols. Q The order of symbols is not significant. COPY START 0 EXTDEF BUFFER, BUFEND, LENGTH EXTREF RDREC, WRREC (symbol name)
  • 79. 79
  • 80. 80
  • 81. 81
  • 82. 2.3.5 Control Sections & Program Linking 82 â–  Figure 2.16, the generated object code. 15 160 0003 0017 CLOOP +JSUB RDREC +STCH BUFFER,X 4B100000 57900000 Q The LOC of all control section is started form 0 Q RDREC is an external reference. Q The assembler has no idea where the control section containing RDREC will be loaded, so it cannot assemble the address. Q The proper address to be inserted at load time. Q Must use extended format instruction for external reference (M records are needed). 190 0028 MAXLEN WORD BUFEND-BUFFER Q An expression involving two external references.
  • 83. 83
  • 84. 84
  • 85. 85
  • 86. 2.3.5 Control Sections & Program Linking 86 Q The loader will add to this data area with the address of BUFEND and subtract from it the address of BUFFER. (COPY and RDREC for MAXLEN) Q Line 190 and 107, in 107, the symbols BUFEND and BUFFER are defined in the same section. Q The assembler must remember in which control section a symbol is defined. Q The assembler allows the same symbol to be used in different control sections, lines 107 and 190. â–  Figure 2.17, two new records. Q Defined record for EXTDEF, relative address. Q Refer record for EXTREF.
  • 87. 87
  • 88. 2.3.5 Control Sections & Program Linking â–  Modification record Q M Q Starting address of the field to be modified, relative to the beginning of the control section (Hex). Q Length of the field to be modified, in half-bytes. Q Modification flag (+ or -). Q External symbol. M^000004^05+RDREC M^000028^06+BUFEND M^000028^06-BUFFER â–  Use Figure 2.8 for program relocation. 88
  • 89. 89
  • 90. 90
  • 91. 2.4 Assembler Design Options 91 2.4.1 Two-Pass Assembler â–  Most assemblers Q Processing the source program into two passes. Q The internal tables and subroutines that are used only during Pass 1. Q The SYMTAB, LITTAB, and OPTAB are used by both passes. â–  The main problems to assemble a program in one pass involves forward references.
  • 92. 2.4.2 One-Pass Assemblers 92 â–  Eliminate forward references Q Data items are defined before they are referenced. Q But, forward references to labels on instructions cannot be eliminated as easily. Q Prohibit forward references to labels. â–  Two types of one-pass assembler. (Fig. 2.18) Q One type produces object code directly in memory for immediate execution. Q The other type produces the usual kind of object program for later execution.
  • 93.
  • 94. 94
  • 95. 95
  • 96. 2.4.2 One-Pass Assemblers 96 â–  Load-and-go one-pass assembler Q The assembler avoids the overhead of writing the object program out and reading it back in. Q The object program is produced in memory, the handling of forward references becomes less difficult. Q Figure 2.19(a), shows the SYMTAB after scanning line 40 of the program in Figure 2.18. Q Since RDREC was not yet defined, the instruction was assembled with no value assigned as the operand address (denote by - - - -).
  • 97. 97
  • 98. 98
  • 99. 2.4.2 One-Pass Assemblers 99 â–  Load-and-go one-pass assembler Q RDREC was then entered into SYMTAB as an undefined symbol, the address of the operand field of the instruction (2013) was inserted. Q Figure 2.19(b), when the symbol ENDFIL was defined (line 45), the assembler placed its value in the SYMTAB entry; it then inserted this value into the instruction operand field (201C). Q At the end of the program, all symbols must be defined without any * in SYMTAB. Q For a load-and-go assembler, the actual address must be known at assembly time.
  • 100. 2.4.2 One-Pass Assemblers 100 â–  Another one-pass assembler by generating OP Q Generate another Text record with correct operand address. Q When the program is loaded, this address will be inserted into the instruction by the action of the loader. Q Figure 2.20, the operand addresses for the instructions on lines 15, 30, and 35 have been generated as 0000. Q When the definition of ENDFIL is encountered on line 45, the third Text record is generated, the value 2024 is to be loaded at location 201C. Q The loader completes forward references.
  • 102. 2.4.2 One-Pass Assemblers 102 â–  In this section, simple one-pass assemblers handled absolute programs (SIC example).
  • 103. 2.4.3 Multi-Pass Assemblers â–  Use EQU, any symbol used on the RHS be defined previously in the source. LOC Pass1 2 3 1000 LDA #0 1000 1000 1000 1003 ALPHA EQU BETA ???? ???? 1003 1003 BETA EQU DELTA ???? 1003 1003 1003 DELTA RESW 1 1003 1003 1003 Q Need 3 passes! â–  Figure 2.21, multi-pass assembler 103