際際滷

際際滷Share a Scribd company logo
UNIT II
ASSEMBLERS
ASSEMBLERS
OUTLINE
 2.1 Basic Assembler Functions
 A simple SIC assembler
 Assembler tables and logic
 2.2 Machine-Dependent Assembler Features
 Instruction formats and addressing modes
 Program relocation
 2.3 Machine-Independent Assembler Features
 2.4 Assembler Design Options
 Two-pass
 One-pass
 Multi-pass
2.1 BASIC ASSEMBLER FUNCTIONS
 Figure 2.1 shows an assembler language program
for SIC.
 The line numbers are for reference only.
 Indexing addressing is indicated by adding the
modifier ,X
 Lines beginning with .contain comments
only.
 Reads records from input device (code F1)
 Copies them to output device (code 05)
 At the end of the file, writes EOF on the output
device, then RSUB to the operating system
assembler_full_slides.ppt
assembler_full_slides.ppt
assembler_full_slides.ppt
2.1 BASIC ASSEMBLER FUNCTIONS
 Assembler directives (pseudo-
instructions)
 START, END, BYTE, WORD, RESB,
RESW.
 These statements are not translated into
machine instructions.
 Instead, they provide instructions to the
assembler itself.
2.1 BASIC ASSEMBLER FUNCTIONS
 Data transfer (RD, WD)
 A buffer is used to store record
 Buffering is necessary for different I/O rates
 The end of each record is marked with a null
character (0016)
 Buffer length is 4096 Bytes
 The end of the file is indicated by a zero-length
record
 When the end of file is detected, the program
writes EOF on the output device and terminates
by RSUB.
 Subroutines (JSUB, RSUB)
 RDREC, WRREC
 Save link (L) register first before nested jump
2.1.1 A SIMPLE SIC ASSEMBLER
 Figure 2.2 shows the generated object code for
each statement.
 Loc gives the machine address in Hex.
 Assume the program starting at address 1000.
 Translation functions
 Translate STL to 14.
 Translate RETADR to 1033.
 Build the machine instructions in the proper
format (,X).
 Translate EOF to 454F46.
 Write the object program and assembly listing
assembler_full_slides.ppt
Forward reference problem
 Reference to a label that is defined later
in the program.
 A forward reference
 In line number10
1000 FIRST STL RETADR 141033
 A reference to a label (RETADR) that is
defined later in the program
 Most assemblers make two passes over the
source program
 Most assemblers make two passes over source
program.
 Pass 1 scans the source for label definitions
and assigns address (Loc).
 Pass 2 performs most of the actual translation.
 Assemblers Functions
 Convert mnemonic operation codes to their
machine language equivalents
 STL to 14
 Convert symbolic operands (referred label)
to their equivalent machine addresses
 RETADR to 1033
 Build the machine instructions in the proper
format
 Convert the data constants to internal
machine representations
 Write the object program and the assembly
listing
The functions of the two passes assembler.
 Pass 1 (define symbol)
 Assign addresses to all statements (generate LOC).
 Check the correctness of Instruction (check with OP table).
 Save the values (address) assigned to all labels into
SYMBOL table for Pass 2.
 Perform some processing of assembler directives.
 Pass 2
 Assemble instructions (op code from OP table, address
from SYMBOL table).
 Generate data values defined by BYTE, WORD.
 Perform processing of assembler directives not done
during Pass 1.
 Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2).
2.1.2 DATA STRUCTURES in ASSEMBLER
 Our simple assembler uses two internal tables: The
OPTAB and SYMTAB.
 OPTAB is used to look up mnemonic operation codes
and translate them to their machine language
equivalents.
 LDA00, STL14, 
 SYMTAB is used to store values (addresses) assigned
to labels.
 COPY1000, FIRST1000 
 Location Counter LOCCTR
 LOCCTR is a variable for assignment addresses.
 LOCCTR is initialized to address specified in START.
 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
 The Operation Code Table (OPTAB)
 Contain the mnemonic operation & its
machine language equivalents (at least).
 Contain instruction format& length.
 Pass 1, OPTAB is used to look up and
validate operation codes.
 Pass 2, OPTAB is used to translate the
operation codes to machine language.
 In SIC/XE, assembler search OPTAB in
Pass 1 to find the instruction length for
incrementing LOCCTR.
 Organize as a hash table (static table).
2.1.2 ASSEMBLER TABLES AND LOGIC
 The Symbol Table (SYMTAB)
 Include the name and value (address) for
each label.
 Include flags to indicate error conditions
 Contain type, length.
 Pass 1, labels are entered into SYMTAB,
along with assigned addresses (from
LOCCTR).
 Pass 2, symbols used as operands are
look up in SYMTAB to obtain the
addresses.
 Organize as a hash table (static table).
 The entries are rarely deleted from table.
2.1.2 ASSEMBLER TABLES AND LOGIC
 Pass 1 usually writes an intermediate file.
 Contain source statement together with
its assigned address, error indicators.
 This file is used as input to Pass 2.
 Figure 2.4 shows the two passes of
assembler.
 Format with fields LABEL, OPCODE,
and OPERAND.
 Denote numeric value with the prefix#.
#[OPERAND]
Pass 1
assembler_full_slides.ppt
Pass 2
assembler_full_slides.ppt
2.2 MACHINE-DEPENDENT ASSEMBLER
FEATURES
 Indirect addressing
 Adding the prefix @ to operand (line 70).
 Immediate operands
 Adding the prefix # to operand (lines 12, 25, 55,
133).
 Extended format
 Adding the prefix + to OP code (lines 15, 35, 65).
 The use of register-register instructions.
 Faster and dont require another memory reference.
Figure 2.5: First
Figure 2.5: RDREC
Figure 2.5: WRREC
Figure 2.5: Example of SIC/XE Program
2.2 MACHINE-DEPENDENT ASSEMBLER
FEATURES
 SIC/XE
 PC-relative/Base-relative addressing op m
 Indirect addressing op @m
 Immediate addressing op #c
 Extended format +op m
 Index addressing op m, X
 register-to-register instructions COMPR
 larger memory multi-programming (program
allocation)
2.2 MACHINE-DEPENDENT
ASSEMBLER FEATURES
 Register translation
 register name (A, X, L, B, S, T, F, PC, SW) and
their values (0, 1, 2, 3, 4, 5, 6, 8, 9)
 preloaded in SYMTAB
 Address translation
 Most register-memory instructions use program
counter relative or base relative addressing
 Format 3: 12-bit disp (address) field
 PC-relative: -2048~2047
 Base-relative: 0~4095
 Format 4: 20-bit address field (absolute
addressing)
2.2.1 INSTRUCTION FORMATS &
ADDRESSING MODES
 The START statement
 Specifies a beginning address of 0.
 Register-register instructions
 CLEAR & TIXR, COMPR
 Register-memory instructions are using
 Program-counter (PC) relative addressing
 The program counter is advanced after each
instruction is fetched and before it is executed.
 PC will contain the address of the next
instruction.
10 0000 FIRST STL RETADR
17202D
TA -(PC) = disp= 30H 3H= 2D
assembler_full_slides.ppt
assembler_full_slides.ppt
Figure 2.6 Program from fig 2.5 with object code
assembler_full_slides.ppt
2.2.1 INSTRUCTION FORMATS &
ADDRESSING MODES
40 0017 J CLOOP 3F2FEC
0006 - 001A= disp= -14
 Base (B), LDB #LENGTH, BASE LENGTH
160 104E STCH BUFFER, X 57C003
TA-(B) = 0036 -(B) = disp= 0036-0033 = 0003
 Extended instruction
15 0006 CLOOP +JSUB RDREC
4B101036
 Immediate instruction
55 0020 LDA #3 010003
133 103C +LDT #4096 75101000
 PC relative + indirect addressing (line 70)
2.2.2 Program Relocation
 Absolute program, relocatable program
2.2.2 PROGRAM RELOCATION
 Note that no matter where the program is loaded,
RDREC is always is 1036 bytes past the starting
address of the program. This means that we can solve
the relocation problem in the following way,
1. When the assembler generates the object code for the
JSUB instruction we are considering it will insert the
address of RDREC relative to the start of the
program.
This is the reason we initialized the location counter
to 0 for the assembly
2. The assembler will also produce the command for
the loader, instructing it to add the beginning address
of the program to address the field in the JSUB
instruction at the load time.
2.2.2 PROGRAM RELOCATION
 Modification record (direct addressing)
 1 M
 2-7 Starting location of the address field to be modified,
relative to the beginning of the program.
 8-9 Length of the address field to be modified, in half
bytes.
M^000007^05
2.3 MACHINE-INDEPENDENT
ASSEMBLER 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 001AENDFIL LDA=CEOF
032010
 Specifies a 3-byte operand whose value is
the character string EOF.
215 1062 WLOOP TD =X05
E32011
 Specifies a 1-byte literal with the
hexadecimal value 05
assembler_full_slides.ppt
RDREC
WRRE
C
Figure 2.9 Program demonstrating additional assembler features
2.3.1 LITERALS
 The difference between literal operands and
immediate operands
 =, #
 Immediate addressing, the operand value is
assembled as part of the machine instruction, no
memory reference.
 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
 At the end of the program (Fig. 2.10).
 Assembler directive LTORG, it creates a literal pool
that contains all of the literal operands used since
the previous LTORG.
assembler_full_slides.ppt
RDREC
WRRE
C
Figure 2.10 Program from figure 2.9 with object code
2.3.1 Literals
 When to use LTORG
 The literal operand would be placed too far away
from the instruction referencing.
 Cannot use PC-relative addressing or Base-
relative addressing to generate Object Program.
 Most assemblers recognize duplicate
literals.
 By comparison of the character strings defining
them.
 =CEOF and =X454F46
2.3.1 LITERALS
 Allow literals that refer to the current value of
the location counter.
 Such literals are sometimes useful for
loading base registers.
LDB =*
; register B=beginning address of
statement=current LOCBASE*
; for base relative addressing
 If a literal =*appeared on line 13 or 55
 Specify an operand with value 0003 (Loc) or
0020 (Loc).
2.3.1 LITERALS
 Literal table (LITTAB)
 Contains the literal name (=CEOF), the
operand value (454F46) and length (3),
and the address (002D).
 Organized as a hash table.
 Pass 1, the assembler creates or searches
LITTAB for the specified literal name.
 Pass 1 encounters a LTORG statement or
the end of the program, the assembler
makes a scan of the literal table.
 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.
 Assembler directive EQU.
 Improved readability in place of numeric values.
+LDT #4096
MAXLEN EQU BUFEND-BUFFER
(4096)
+LDT #MAXLEN
 Use EQU in defining mnemonic names for
registers.
 Registers A, X, L can be used by numbers 0, 1,
2.
2.3.2 SYMBOL-DEFINING STATEMENTS
 The standard names reflect the usage of the
registers.
BASE EQUR1
COUNT EQUR2
INDEX EQUR3
 Assembler directive ORG
 Use to indirectly assign values to symbols.
ORG value
 The assembler resets its LOCCTR to the
specified value.
 ORG can be useful in label definition.
2.3.2 SYMBOL-DEFINING STATEMENTS
 The location counter is used to control
assignment of storage in the object program
 In most cases, altering its value would
result in an incorrect assembly.
 ORG is used
http://home.educities.edu.tw/wanker742126
/index.html
 SYMBOL is 6-byte, VALUE is 3-byte,
and FLAGS is 2-byte.
2.3.2 SYMBOL-DEFINING STATEMENTS
 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
ORGSTAB+ 1100
2.3.2 SYMBOL-DEFINING STATEMENTS
 All terms used to specify the value of the
new symbol ---must have been defined
previously in the program.
...
BETA EQUALPHA
ALPHA RESW 1
...
Need 2 passes
2.3.2 SYMBOL-DEFINING STATEMENTS
 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
Need 3 passes
2.3.3 EXPRESSIONS
 Allow arithmetic expressions formed
 Using the operators +, -, , /.
 Division is usually defined to produce an integer
result.
 Expression may be constants, user-defined symbols,
or special terms.
106 1036 BUFEND EQU *
 Gives BUFEND a value that is the address of the next
byte after the buffer area.
 Absolute expressions or relative expressions
 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
 Both BUFEND and BUFFER are relative terms.
 The expression represents absolute value: the
difference between the two addresses.
 Loc =1000 (Hex)
 The value that is associated with the symbol that
appears in the source statement.
 BUFEND+BUFFER, 100-BUFFER,
3*BUFFER represent neither absolute values
nor locations.
 Symbol tables entries
2.3.4 PROGRAM BLOCKS
 The source program logically contained main,
subroutines, data areas.
 In a single block of object code.
 More flexible (Different blocks)
 Generate machine instructions (codes) and
data in a different order from the
corresponding source statements.
 Program blocks
 Refer to segments of code that are rearranged
within a single object program unit.
 Control sections
 Refer to segments of code that are translated
into independent object program units.
2.3.4 PROGRAM BLOCKS
 Three blocks, Figure 2.11
 Default (USE), CDATA (USE CDATA),
CBLKS (USE CBLKS).
 Assembler directive USE
 Indicates which portions of the source
program blocks.
 At the beginning of the program, statements
are assumed to be part of the default block.
 Lines 92, 103, 123, 183, 208, 252.
 Each program block may contain several
separate segments.
 The assembler will rearrange these segments
to gather together the pieces of each block.
Main
RDREC
WRRE
C
Figure 2.11 Example of the Program with Multiple Program blocks
2.3.4 PROGRAM BLOCKS
 Pass 1, Figure 2.12
 The block number is started form 0.
 A separate location counter for each program block.
 The location counter for a block is initialized to 0
when the block is first begun.
 Assign each block a starting address in the object
program (location 0).
 Labels, block name or block number, relative addr.
 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)
assembler_full_slides.ppt
assembler_full_slides.ppt
Figure 2.12 Program from figure 2.11 with object code
2.3.4 PROGRAM BLOCKS
 Pass 2, Figure 2.12
 The assembler needs the address for each symbol
relative to the start of the object program.
 Loc shows the relative address and block number.
 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
 Separation of the program into blocks.
 Because the large buffer (CBLKS) is moved to the
end of the object program.
 No longer need extended format, base register, simply
a LTORG statement.
 No need Modification records.
 Improve program readability.
 Figure 2.13
 Reflect the starting address of the block as well as the
relative location of the code within the block.
 Figure 2.14
 Loader simply loads the object code from each record
at the dictated.
 CDATA(1) & CBLKS(1) are not actually present in
OP.
2.3.4 PROGRAM BLOCKS
Figure 2.13 Object Program corresponding to figure 2.11
Figure 2.14 Program blocks from fig 2.11 traced through the assembly
and loading processes
2.3.5 CONTROL SECTIONS & PROGRAM
LINKING
 Control section
 Handling of programs that consist of multiple
control sections.
 Each control section is a part of the program.
 Can be assembled, loaded and relocated
independently.
 Different control sections are most often used for
subroutines or other logical subdivisions of a
program.
 The programmer can assemble, load, and manipulate
each of these control sections separately.
 More Flexibility then the previous.
 Linking control sections together.
2.3.5 CONTROL SECTIONS & PROGRAM
LINKING
 External references (external symbol references)
 Instructions in one control section might need to refer
to instructions or data located in another section.
 Figure 2.15, multiple control sections.
 Three sections, main COPY, RDREC, WRREC.
 Assembler directive CSECT.
 Assembler directives EXTDEF and EXTREF for
external symbols.
 The order of symbols is not significant.
COPY START 0
EXTDEF BUFFER,
BUFEND, LENGTH
EXTREF RDREC,
WRREC (symbol name)
assembler_full_slides.ppt
assembler_full_slides.ppt
Figure 2.15 Illustrations of Program linking and control sections
2.3.5 CONTROL SECTIONS & PROGRAM
LINKING
 Figure 2.16, the generated object code.
15 0003 CLOOP +JSUB
RDREC 4B100000
160 0017 +STCH BUFFER,X
57900000
 The LOC of all control section is started form 0
 RDREC is an external reference.
 The assembler has no idea where the control section containing
RDREC will be loaded, so it cannot assemble the address.
 The proper address to be inserted at load time.
 Must use extended format instruction for external reference (M
records are needed).
190 0028 MAXLEN WORD BUFEND-
BUFFER
 An expression involving two external references.
assembler_full_slides.ppt
assembler_full_slides.ppt
Figure 2.16 Program from fig 2.15 with object code.
2.3.5 CONTROL SECTIONS & PROGRAM
LINKING
 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)
 Line 190 and 107, in 107, the symbols BUFEND
and BUFFER are defined in the same section.
 The assembler must remember in which control
section a symbol is defined.
 The assembler allows the same symbol to be used in
different control sections, lines 107 and 190.
 Figure 2.17, two new records.
 Defined record for EXTDEF, relative address.
 Refer record for EXTREF.
assembler_full_slides.ppt
2.3.5 CONTROL SECTIONS & PROGRAM
LINKING
 Modification record
 M
 Starting address of the field to be modified,
relative to the beginning of the control section
(Hex).
 Length of the field to be modified, in half-bytes.
 Modification flag(+ or -).
 External symbol.
M^000004^05+RDREC
M^000028^06+BUFEND
M^000028^06-BUFFER
 Use Figure 2.8 for program relocation.
assembler_full_slides.ppt
Figure 2.17 Object Program corresponding to fig 2.15
2.4 ASSEMBLER DESIGN OPTIONS
2.4.1 TWO-PASS ASSEMBLER
 Most assemblers
 Processing the source program into two
passes.
 The internal tables and subroutines that
are used only during Pass 1.
 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
 Eliminate forward references
 Data items are defined before they are
referenced.
 But, forward references to labels on
instructions cannot be eliminated as easily.
 Prohibit forward references to labels.
 Two types of one-pass assembler. (Fig. 2.18)
 One type produces object code directly in
memory for immediate execution.
 The other type produces the usual kind of
object program for later execution.
assembler_full_slides.ppt
assembler_full_slides.ppt
Figure 2.18 Sample Program for a one Pass assembler.
2.4.2 ONE-PASS ASSEMBLERS
 Load-and-go one-pass assembler
 The assembler avoids the overhead of writing the
object program out and reading it back in.
 The object program is produced in memory, the
handling of forward references becomes less
difficult.
 Figure 2.19(a), shows the SYMTAB after scanning
line 40 of the program in Figure 2.18.
 Since RDREC was not yet defined, the instruction
was assembled with no value assigned as the
operand address (denote by ----).
Figure 2.19(a) Object code in memory and symbol table entries for the
program in fig 2.18 after scanning line 40
Figure 2.19(b) Object code in memory and symbol table entries for the
program in fig 2.18 after scanning line 150
2.4.2 ONE-PASS ASSEMBLERS
 Load-and-go one-pass assembler
 RDREC was then entered into SYMTAB as an
undefined symbol, the address of the operand
field of the instruction (2013) was inserted.
 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).
 At the end of the program, all symbols must
be defined without any * in SYMTAB.
 For a load-and-go assembler, the actual
address must be known at .
2.4.2 ONE-PASS ASSEMBLERS
 Another one-pass assembler by generating OP
 Generate another Text record with correct
operand address.
 When the program is loaded, this address will be
inserted into the instruction by the action of the
loader.
 Figure 2.20, the operand addresses for the
instructions on lines 15, 30, and 35 have been
generated as 0000.
 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.
 The loader completes forward references.
Figure 2.20 Object Program for one-pass assembler for Program in fig 2.18
2.4.2 ONE-PASS ASSEMBLERS
 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 RESW1 1003 1003 1003
 Need 3 passes!
 Figure 2.21, multi-pass assembler
(a)
2.4.3 MULTI-PASS ASSEMBLERS
(b)
2.4.3 MULTI-PASS ASSEMBLERS
(c)
2.4.3 MULTI-PASS ASSEMBLERS
(d)
2.4.3 MULTI-PASS ASSEMBLERS
(e)
2.4.3 MULTI-PASS ASSEMBLERS
(f)

More Related Content

Similar to assembler_full_slides.ppt (20)

Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
Omar Sanchez
Assembler
AssemblerAssembler
Assembler
SheetalAwate2
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
desta_gebre
Assembler (2)
Assembler (2)Assembler (2)
Assembler (2)
Vaibhav Bajaj
Lec 14-Instruction Set Architecture.pptx
Lec 14-Instruction Set Architecture.pptxLec 14-Instruction Set Architecture.pptx
Lec 14-Instruction Set Architecture.pptx
afafkainat
Computer Organization
Computer Organization Computer Organization
Computer Organization
Radhika Talaviya
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
Radhika Talaviya
Assembly Language for as level computer science
Assembly Language for as level computer scienceAssembly Language for as level computer science
Assembly Language for as level computer science
variedongz
heuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptxheuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptx
christinamary2620
Handout#10
Handout#10Handout#10
Handout#10
Sunita Milind Dol
module 4.docx
module 4.docxmodule 4.docx
module 4.docx
GOKULDEV20
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
Rai 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 control
Rai University
LCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyy
LCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyyLCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyy
LCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyy
muradportal
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
Rai 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 control
Rai University
Instruction codes
Instruction codesInstruction codes
Instruction codes
pradeepa velmurugan
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
Dilum Bandara
Assembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdfAssembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdf
ahmedmohammed246810a
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya
Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
Omar Sanchez
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
desta_gebre
Lec 14-Instruction Set Architecture.pptx
Lec 14-Instruction Set Architecture.pptxLec 14-Instruction Set Architecture.pptx
Lec 14-Instruction Set Architecture.pptx
afafkainat
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
Radhika Talaviya
Assembly Language for as level computer science
Assembly Language for as level computer scienceAssembly Language for as level computer science
Assembly Language for as level computer science
variedongz
heuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptxheuring_jordan_----------ch02(1) (1).pptx
heuring_jordan_----------ch02(1) (1).pptx
christinamary2620
module 4.docx
module 4.docxmodule 4.docx
module 4.docx
GOKULDEV20
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
Rai 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 control
Rai University
LCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyy
LCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyyLCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyy
LCDF3_Chap_10_P2.pptytttttyyyyyyyyyyyyyy
muradportal
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
Rai 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 control
Rai University
Instruction Set Architecture
Instruction Set ArchitectureInstruction Set Architecture
Instruction Set Architecture
Dilum Bandara
Assembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdfAssembly_80x86- Assembly languages programming and 80x861.pdf
Assembly_80x86- Assembly languages programming and 80x861.pdf
ahmedmohammed246810a
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
Kamal Acharya

Recently uploaded (20)

Kamal 2, new features and practical examples
Kamal 2, new features and practical examplesKamal 2, new features and practical examples
Kamal 2, new features and practical examples
Igor Aleksandrov
22PCOAM16 _ML_ Unit 2 Full unit notes.pdf
22PCOAM16 _ML_ Unit 2 Full unit notes.pdf22PCOAM16 _ML_ Unit 2 Full unit notes.pdf
22PCOAM16 _ML_ Unit 2 Full unit notes.pdf
Guru Nanak Technical Institutions
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
CNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECHCNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECH
C Sai Kiran
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
Industry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and BeyondIndustry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and Beyond
GtxDriver
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
yadavchandan322
Why the Engineering Model is Key to Successful Projects
Why the Engineering Model is Key to Successful ProjectsWhy the Engineering Model is Key to Successful Projects
Why the Engineering Model is Key to Successful Projects
Maadhu Creatives-Model Making Company
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
sensors utilized in agro meteorology sdes
sensors utilized in agro meteorology sdessensors utilized in agro meteorology sdes
sensors utilized in agro meteorology sdes
Jenitha Rajadurai
PLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amityPLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amity
UrjaMoon
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
Guru Nanak Technical Institutions
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control Monthly - April 2025
Water Industry Process Automation & Control
Supervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine LearningSupervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine Learning
ShivarkarSandip
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
windrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptxwindrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptx
nukeshpandey5678
Mastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdfMastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdf
Brion Mario
Kamal 2, new features and practical examples
Kamal 2, new features and practical examplesKamal 2, new features and practical examples
Kamal 2, new features and practical examples
Igor Aleksandrov
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
CNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECHCNC Technology Unit-4 for IV Year 24-25 MECH
CNC Technology Unit-4 for IV Year 24-25 MECH
C Sai Kiran
Virtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-RevolutionVirtual Power plants-Cleantech-Revolution
Virtual Power plants-Cleantech-Revolution
Ashoka Saket
CNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECHCNC Technology Unit-1 for IV Year 24-25 MECH
CNC Technology Unit-1 for IV Year 24-25 MECH
C Sai Kiran
Intro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching schemeIntro PPT SY_HONORS.pptx- Teaching scheme
Intro PPT SY_HONORS.pptx- Teaching scheme
Priyanka Dange
Industry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and BeyondIndustry 4.0: Transforming Modern Manufacturing and Beyond
Industry 4.0: Transforming Modern Manufacturing and Beyond
GtxDriver
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
PROJECT REPORT ON PASTA MACHINE - KP AUTOMATIONS - PASTA MAKING MACHINE PROJE...
yadavchandan322
02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf02.BigDataAnalytics curso de Legsi (1).pdf
02.BigDataAnalytics curso de Legsi (1).pdf
ruioliveira1921
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...UHV UNIT-5    IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON ...
ariomthermal2031
sensors utilized in agro meteorology sdes
sensors utilized in agro meteorology sdessensors utilized in agro meteorology sdes
sensors utilized in agro meteorology sdes
Jenitha Rajadurai
PLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amityPLANT CELL REACTORS presenation PTC amity
PLANT CELL REACTORS presenation PTC amity
UrjaMoon
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
22PCOAM16_ML_Unit 1 notes & Question Bank with answers.pdf
Guru Nanak Technical Institutions
Supervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine LearningSupervised Learning Ensemble Techniques Machine Learning
Supervised Learning Ensemble Techniques Machine Learning
ShivarkarSandip
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Intro of Airport Engg..pptx-Definition of airport engineering and airport pla...
Priyanka Dange
windrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptxwindrose1.ppt for seminar of civil .pptx
windrose1.ppt for seminar of civil .pptx
nukeshpandey5678
Mastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdfMastering Secure Login Mechanisms for React Apps.pdf
Mastering Secure Login Mechanisms for React Apps.pdf
Brion Mario

assembler_full_slides.ppt

  • 3. OUTLINE 2.1 Basic Assembler Functions A simple SIC assembler Assembler tables and logic 2.2 Machine-Dependent Assembler Features Instruction formats and addressing modes Program relocation 2.3 Machine-Independent Assembler Features 2.4 Assembler Design Options Two-pass One-pass Multi-pass
  • 4. 2.1 BASIC ASSEMBLER FUNCTIONS Figure 2.1 shows an assembler language program for SIC. The line numbers are for reference only. Indexing addressing is indicated by adding the modifier ,X Lines beginning with .contain comments only. Reads records from input device (code F1) Copies them to output device (code 05) At the end of the file, writes EOF on the output device, then RSUB to the operating system
  • 8. 2.1 BASIC ASSEMBLER FUNCTIONS Assembler directives (pseudo- instructions) START, END, BYTE, WORD, RESB, RESW. These statements are not translated into machine instructions. Instead, they provide instructions to the assembler itself.
  • 9. 2.1 BASIC ASSEMBLER FUNCTIONS Data transfer (RD, WD) A buffer is used to store record Buffering is necessary for different I/O rates The end of each record is marked with a null character (0016) Buffer length is 4096 Bytes The end of the file is indicated by a zero-length record When the end of file is detected, the program writes EOF on the output device and terminates by RSUB. Subroutines (JSUB, RSUB) RDREC, WRREC Save link (L) register first before nested jump
  • 10. 2.1.1 A SIMPLE SIC ASSEMBLER Figure 2.2 shows the generated object code for each statement. Loc gives the machine address in Hex. Assume the program starting at address 1000. Translation functions Translate STL to 14. Translate RETADR to 1033. Build the machine instructions in the proper format (,X). Translate EOF to 454F46. Write the object program and assembly listing
  • 12. Forward reference problem Reference to a label that is defined later in the program.
  • 13. A forward reference In line number10 1000 FIRST STL RETADR 141033 A reference to a label (RETADR) that is defined later in the program Most assemblers make two passes over the source program Most assemblers make two passes over source program. Pass 1 scans the source for label definitions and assigns address (Loc). Pass 2 performs most of the actual translation.
  • 14. Assemblers Functions Convert mnemonic operation codes to their machine language equivalents STL to 14 Convert symbolic operands (referred label) to their equivalent machine addresses RETADR to 1033 Build the machine instructions in the proper format Convert the data constants to internal machine representations Write the object program and the assembly listing
  • 15. The functions of the two passes assembler. Pass 1 (define symbol) Assign addresses to all statements (generate LOC). Check the correctness of Instruction (check with OP table). Save the values (address) assigned to all labels into SYMBOL table for Pass 2. Perform some processing of assembler directives. Pass 2 Assemble instructions (op code from OP table, address from SYMBOL table). Generate data values defined by BYTE, WORD. Perform processing of assembler directives not done during Pass 1. Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2).
  • 16. 2.1.2 DATA STRUCTURES in ASSEMBLER Our simple assembler uses two internal tables: The OPTAB and SYMTAB. OPTAB is used to look up mnemonic operation codes and translate them to their machine language equivalents. LDA00, STL14, SYMTAB is used to store values (addresses) assigned to labels. COPY1000, FIRST1000 Location Counter LOCCTR LOCCTR is a variable for assignment addresses. LOCCTR is initialized to address specified in START. When reach a label, the current value of LOCCTR gives the address to be associated with that label.
  • 17. 2.1.2 ASSEMBLER TABLES AND LOGIC The Operation Code Table (OPTAB) Contain the mnemonic operation & its machine language equivalents (at least). Contain instruction format& length. Pass 1, OPTAB is used to look up and validate operation codes. Pass 2, OPTAB is used to translate the operation codes to machine language. In SIC/XE, assembler search OPTAB in Pass 1 to find the instruction length for incrementing LOCCTR. Organize as a hash table (static table).
  • 18. 2.1.2 ASSEMBLER TABLES AND LOGIC The Symbol Table (SYMTAB) Include the name and value (address) for each label. Include flags to indicate error conditions Contain type, length. Pass 1, labels are entered into SYMTAB, along with assigned addresses (from LOCCTR). Pass 2, symbols used as operands are look up in SYMTAB to obtain the addresses. Organize as a hash table (static table). The entries are rarely deleted from table.
  • 19. 2.1.2 ASSEMBLER TABLES AND LOGIC Pass 1 usually writes an intermediate file. Contain source statement together with its assigned address, error indicators. This file is used as input to Pass 2. Figure 2.4 shows the two passes of assembler. Format with fields LABEL, OPCODE, and OPERAND. Denote numeric value with the prefix#. #[OPERAND]
  • 24. 2.2 MACHINE-DEPENDENT ASSEMBLER FEATURES Indirect addressing Adding the prefix @ to operand (line 70). Immediate operands Adding the prefix # to operand (lines 12, 25, 55, 133). Extended format Adding the prefix + to OP code (lines 15, 35, 65). The use of register-register instructions. Faster and dont require another memory reference.
  • 27. Figure 2.5: WRREC Figure 2.5: Example of SIC/XE Program
  • 28. 2.2 MACHINE-DEPENDENT ASSEMBLER FEATURES SIC/XE PC-relative/Base-relative addressing op m Indirect addressing op @m Immediate addressing op #c Extended format +op m Index addressing op m, X register-to-register instructions COMPR larger memory multi-programming (program allocation)
  • 29. 2.2 MACHINE-DEPENDENT ASSEMBLER FEATURES Register translation register name (A, X, L, B, S, T, F, PC, SW) and their values (0, 1, 2, 3, 4, 5, 6, 8, 9) preloaded in SYMTAB Address translation Most register-memory instructions use program counter relative or base relative addressing Format 3: 12-bit disp (address) field PC-relative: -2048~2047 Base-relative: 0~4095 Format 4: 20-bit address field (absolute addressing)
  • 30. 2.2.1 INSTRUCTION FORMATS & ADDRESSING MODES The START statement Specifies a beginning address of 0. Register-register instructions CLEAR & TIXR, COMPR Register-memory instructions are using Program-counter (PC) relative addressing The program counter is advanced after each instruction is fetched and before it is executed. PC will contain the address of the next instruction. 10 0000 FIRST STL RETADR 17202D TA -(PC) = disp= 30H 3H= 2D
  • 33. Figure 2.6 Program from fig 2.5 with object code
  • 35. 2.2.1 INSTRUCTION FORMATS & ADDRESSING MODES 40 0017 J CLOOP 3F2FEC 0006 - 001A= disp= -14 Base (B), LDB #LENGTH, BASE LENGTH 160 104E STCH BUFFER, X 57C003 TA-(B) = 0036 -(B) = disp= 0036-0033 = 0003 Extended instruction 15 0006 CLOOP +JSUB RDREC 4B101036 Immediate instruction 55 0020 LDA #3 010003 133 103C +LDT #4096 75101000 PC relative + indirect addressing (line 70)
  • 36. 2.2.2 Program Relocation Absolute program, relocatable program
  • 37. 2.2.2 PROGRAM RELOCATION Note that no matter where the program is loaded, RDREC is always is 1036 bytes past the starting address of the program. This means that we can solve the relocation problem in the following way, 1. When the assembler generates the object code for the JSUB instruction we are considering it will insert the address of RDREC relative to the start of the program. This is the reason we initialized the location counter to 0 for the assembly 2. The assembler will also produce the command for the loader, instructing it to add the beginning address of the program to address the field in the JSUB instruction at the load time.
  • 38. 2.2.2 PROGRAM RELOCATION Modification record (direct addressing) 1 M 2-7 Starting location of the address field to be modified, relative to the beginning of the program. 8-9 Length of the address field to be modified, in half bytes. M^000007^05
  • 39. 2.3 MACHINE-INDEPENDENT ASSEMBLER 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 001AENDFIL LDA=CEOF 032010 Specifies a 3-byte operand whose value is the character string EOF. 215 1062 WLOOP TD =X05 E32011 Specifies a 1-byte literal with the hexadecimal value 05
  • 41. RDREC
  • 42. WRRE C Figure 2.9 Program demonstrating additional assembler features
  • 43. 2.3.1 LITERALS The difference between literal operands and immediate operands =, # Immediate addressing, the operand value is assembled as part of the machine instruction, no memory reference. 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 At the end of the program (Fig. 2.10). Assembler directive LTORG, it creates a literal pool that contains all of the literal operands used since the previous LTORG.
  • 45. RDREC
  • 46. WRRE C Figure 2.10 Program from figure 2.9 with object code
  • 47. 2.3.1 Literals When to use LTORG The literal operand would be placed too far away from the instruction referencing. Cannot use PC-relative addressing or Base- relative addressing to generate Object Program. Most assemblers recognize duplicate literals. By comparison of the character strings defining them. =CEOF and =X454F46
  • 48. 2.3.1 LITERALS Allow literals that refer to the current value of the location counter. Such literals are sometimes useful for loading base registers. LDB =* ; register B=beginning address of statement=current LOCBASE* ; for base relative addressing If a literal =*appeared on line 13 or 55 Specify an operand with value 0003 (Loc) or 0020 (Loc).
  • 49. 2.3.1 LITERALS Literal table (LITTAB) Contains the literal name (=CEOF), the operand value (454F46) and length (3), and the address (002D). Organized as a hash table. Pass 1, the assembler creates or searches LITTAB for the specified literal name. Pass 1 encounters a LTORG statement or the end of the program, the assembler makes a scan of the literal table. Pass 2, the operand address for use in generating OC is obtained by searching LITTAB.
  • 50. 2.3.2 SYMBOL-DEFINING STATEMENTS Allow the programmer to define symbols and specify their values. Assembler directive EQU. Improved readability in place of numeric values. +LDT #4096 MAXLEN EQU BUFEND-BUFFER (4096) +LDT #MAXLEN Use EQU in defining mnemonic names for registers. Registers A, X, L can be used by numbers 0, 1, 2.
  • 51. 2.3.2 SYMBOL-DEFINING STATEMENTS The standard names reflect the usage of the registers. BASE EQUR1 COUNT EQUR2 INDEX EQUR3 Assembler directive ORG Use to indirectly assign values to symbols. ORG value The assembler resets its LOCCTR to the specified value. ORG can be useful in label definition.
  • 52. 2.3.2 SYMBOL-DEFINING STATEMENTS The location counter is used to control assignment of storage in the object program In most cases, altering its value would result in an incorrect assembly. ORG is used http://home.educities.edu.tw/wanker742126 /index.html SYMBOL is 6-byte, VALUE is 3-byte, and FLAGS is 2-byte.
  • 53. 2.3.2 SYMBOL-DEFINING STATEMENTS 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.
  • 54. 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 ORGSTAB+ 1100
  • 55. 2.3.2 SYMBOL-DEFINING STATEMENTS All terms used to specify the value of the new symbol ---must have been defined previously in the program. ... BETA EQUALPHA ALPHA RESW 1 ... Need 2 passes
  • 56. 2.3.2 SYMBOL-DEFINING STATEMENTS 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 Need 3 passes
  • 57. 2.3.3 EXPRESSIONS Allow arithmetic expressions formed Using the operators +, -, , /. Division is usually defined to produce an integer result. Expression may be constants, user-defined symbols, or special terms. 106 1036 BUFEND EQU * Gives BUFEND a value that is the address of the next byte after the buffer area. Absolute expressions or relative expressions A relative term or expression represents some value (S+r), S: starting address, r: the relative value.
  • 58. 2.3.3 EXPRESSIONS 107 1000 MAXLEN EQU BUFEND-BUFFER Both BUFEND and BUFFER are relative terms. The expression represents absolute value: the difference between the two addresses. Loc =1000 (Hex) The value that is associated with the symbol that appears in the source statement. BUFEND+BUFFER, 100-BUFFER, 3*BUFFER represent neither absolute values nor locations. Symbol tables entries
  • 59. 2.3.4 PROGRAM BLOCKS The source program logically contained main, subroutines, data areas. In a single block of object code. More flexible (Different blocks) Generate machine instructions (codes) and data in a different order from the corresponding source statements. Program blocks Refer to segments of code that are rearranged within a single object program unit. Control sections Refer to segments of code that are translated into independent object program units.
  • 60. 2.3.4 PROGRAM BLOCKS Three blocks, Figure 2.11 Default (USE), CDATA (USE CDATA), CBLKS (USE CBLKS). Assembler directive USE Indicates which portions of the source program blocks. At the beginning of the program, statements are assumed to be part of the default block. Lines 92, 103, 123, 183, 208, 252. Each program block may contain several separate segments. The assembler will rearrange these segments to gather together the pieces of each block.
  • 61. Main
  • 62. RDREC
  • 63. WRRE C Figure 2.11 Example of the Program with Multiple Program blocks
  • 64. 2.3.4 PROGRAM BLOCKS Pass 1, Figure 2.12 The block number is started form 0. A separate location counter for each program block. The location counter for a block is initialized to 0 when the block is first begun. Assign each block a starting address in the object program (location 0). Labels, block name or block number, relative addr. 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)
  • 67. Figure 2.12 Program from figure 2.11 with object code
  • 68. 2.3.4 PROGRAM BLOCKS Pass 2, Figure 2.12 The assembler needs the address for each symbol relative to the start of the object program. Loc shows the relative address and block number. 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
  • 69. 2.3.4 PROGRAM BLOCKS Separation of the program into blocks. Because the large buffer (CBLKS) is moved to the end of the object program. No longer need extended format, base register, simply a LTORG statement. No need Modification records. Improve program readability. Figure 2.13 Reflect the starting address of the block as well as the relative location of the code within the block. Figure 2.14 Loader simply loads the object code from each record at the dictated. CDATA(1) & CBLKS(1) are not actually present in OP.
  • 70. 2.3.4 PROGRAM BLOCKS Figure 2.13 Object Program corresponding to figure 2.11
  • 71. Figure 2.14 Program blocks from fig 2.11 traced through the assembly and loading processes
  • 72. 2.3.5 CONTROL SECTIONS & PROGRAM LINKING Control section Handling of programs that consist of multiple control sections. Each control section is a part of the program. Can be assembled, loaded and relocated independently. Different control sections are most often used for subroutines or other logical subdivisions of a program. The programmer can assemble, load, and manipulate each of these control sections separately. More Flexibility then the previous. Linking control sections together.
  • 73. 2.3.5 CONTROL SECTIONS & PROGRAM LINKING External references (external symbol references) Instructions in one control section might need to refer to instructions or data located in another section. Figure 2.15, multiple control sections. Three sections, main COPY, RDREC, WRREC. Assembler directive CSECT. Assembler directives EXTDEF and EXTREF for external symbols. The order of symbols is not significant. COPY START 0 EXTDEF BUFFER, BUFEND, LENGTH EXTREF RDREC, WRREC (symbol name)
  • 76. Figure 2.15 Illustrations of Program linking and control sections
  • 77. 2.3.5 CONTROL SECTIONS & PROGRAM LINKING Figure 2.16, the generated object code. 15 0003 CLOOP +JSUB RDREC 4B100000 160 0017 +STCH BUFFER,X 57900000 The LOC of all control section is started form 0 RDREC is an external reference. The assembler has no idea where the control section containing RDREC will be loaded, so it cannot assemble the address. The proper address to be inserted at load time. Must use extended format instruction for external reference (M records are needed). 190 0028 MAXLEN WORD BUFEND- BUFFER An expression involving two external references.
  • 80. Figure 2.16 Program from fig 2.15 with object code.
  • 81. 2.3.5 CONTROL SECTIONS & PROGRAM LINKING 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) Line 190 and 107, in 107, the symbols BUFEND and BUFFER are defined in the same section. The assembler must remember in which control section a symbol is defined. The assembler allows the same symbol to be used in different control sections, lines 107 and 190. Figure 2.17, two new records. Defined record for EXTDEF, relative address. Refer record for EXTREF.
  • 83. 2.3.5 CONTROL SECTIONS & PROGRAM LINKING Modification record M Starting address of the field to be modified, relative to the beginning of the control section (Hex). Length of the field to be modified, in half-bytes. Modification flag(+ or -). External symbol. M^000004^05+RDREC M^000028^06+BUFEND M^000028^06-BUFFER Use Figure 2.8 for program relocation.
  • 85. Figure 2.17 Object Program corresponding to fig 2.15
  • 86. 2.4 ASSEMBLER DESIGN OPTIONS 2.4.1 TWO-PASS ASSEMBLER Most assemblers Processing the source program into two passes. The internal tables and subroutines that are used only during Pass 1. The SYMTAB, LITTAB, and OPTAB are used by both passes. The main problems to assemble a program in one pass involves forward references.
  • 87. 2.4.2 ONE-PASS ASSEMBLERS Eliminate forward references Data items are defined before they are referenced. But, forward references to labels on instructions cannot be eliminated as easily. Prohibit forward references to labels. Two types of one-pass assembler. (Fig. 2.18) One type produces object code directly in memory for immediate execution. The other type produces the usual kind of object program for later execution.
  • 90. Figure 2.18 Sample Program for a one Pass assembler.
  • 91. 2.4.2 ONE-PASS ASSEMBLERS Load-and-go one-pass assembler The assembler avoids the overhead of writing the object program out and reading it back in. The object program is produced in memory, the handling of forward references becomes less difficult. Figure 2.19(a), shows the SYMTAB after scanning line 40 of the program in Figure 2.18. Since RDREC was not yet defined, the instruction was assembled with no value assigned as the operand address (denote by ----).
  • 92. Figure 2.19(a) Object code in memory and symbol table entries for the program in fig 2.18 after scanning line 40
  • 93. Figure 2.19(b) Object code in memory and symbol table entries for the program in fig 2.18 after scanning line 150
  • 94. 2.4.2 ONE-PASS ASSEMBLERS Load-and-go one-pass assembler RDREC was then entered into SYMTAB as an undefined symbol, the address of the operand field of the instruction (2013) was inserted. 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). At the end of the program, all symbols must be defined without any * in SYMTAB. For a load-and-go assembler, the actual address must be known at .
  • 95. 2.4.2 ONE-PASS ASSEMBLERS Another one-pass assembler by generating OP Generate another Text record with correct operand address. When the program is loaded, this address will be inserted into the instruction by the action of the loader. Figure 2.20, the operand addresses for the instructions on lines 15, 30, and 35 have been generated as 0000. 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. The loader completes forward references.
  • 96. Figure 2.20 Object Program for one-pass assembler for Program in fig 2.18
  • 97. 2.4.2 ONE-PASS ASSEMBLERS In this section, simple one-pass assemblers handled absolute programs (SIC example).
  • 98. 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 RESW1 1003 1003 1003 Need 3 passes! Figure 2.21, multi-pass assembler (a)