CS 9303 SYSTEM SOFTWARE

ÌNTERNALS
V.P JAYA CHÌTRA
Computer Technology Dept
Course Objective
This course aids the learners to understand the basic functions
of Software components, viz. Assemblers ,Loaders Linkers,
Macro processors and Compilers. Also discusses about design
and implementation of Assemblers and Macro processor with
examples. Ìt then Ìntroduces the concept of Virtual machine
with object-oriented features supported. The performance of
Emulation Techniques were also analyzed. As a prerequisite
the learner should have had some exposure to elementary data
structures and Assembly language.
$COPE
At the end of the course, the learners will be able to:
Design and Ìmplement Assemblers.
Understand and Analyze the features of Loaders and Linkers.
Design and implement Macro processor.
Understand about the design and operations of Compilers.
Analyze the implementation of Virtual machine by supporting
object ÷ oriented programming features.
Analyze the performance of emulation techniques
&% PLA
&% 1
&3it PIa3
Title Sessions
Machine Ìnstructions and programs Session 1
Assemblers ÷Basic Assemblers functions Session 2
Simple SÌC Assembler Session 3
Assembler algorithm and data structures Session 4
Machine-dependent Assembler features
i)Ìnstruction formats and Addressing
modes
Session 5
Co3td.
Title Sessions
Machine-dependent Assembler features
ii)Program Relocation
Session 6
Machine-independent Assembler features
i)Litrerals ii)Statements iii)Expressions
Session 7
Machine-independent Assembler features
iv)Program blocks v)Control sections and
Program Linking
Session 8
&3it 1:Review of Computer
Architecture
&3it 1:
Review of Computer Architecture
Objective:
Ìn this unit the basic concepts of program assembly is explained
using SÌC machine. This begins with the discussion of the
relationships between system software and machine
Architecture. The assemblers machine-dependent and Machine-
Ìndependent features is also discussed. The essentials of a one
and two-pass assembler is also presented. As a result this unit
aids in design and implementation of an Assembler.
achi3e 3structio3s a3d programs
$essio3 1
3troductio3 to system software
$oftware
AppIicatio3 software usually used by end-user
· Concerned with the solution of some problem, using the
computer as a tool.
$ystem software
· System software consists of a variety of programs that support
the operation of a computer.
· Acts as an intermediary between users and hardware.
· Creates a virtual environment for the user that hides the actual
computer architecture.
· Virtual Machine: Set of services and resources created by
the system software and seen by the user.
· The characteristic in which most system software differ from
application software is machi3e depe3de3cy.
$ystem software.
System
Software
Hardware
3terface B
Actual
Machine
Ìnterface
Virtual
Machine
Ìnterface
Ìnterface A
Virtual Machine
Figure 1.1 The Role of System Software
$ystem software.
compo3e3ts
La3guage $ervices
Write programs in a high-level, user-oriented language, and then
execute them ÷i.e Translator
· assembler
· compiler
· interpreter
emory ma3agers
Allocate and retrieve memory space
· loader
· linker
other utiIities
Collections of library routines that provide services either to user or
system routines.
· DBMS, editor, debugger, ...
$ystem software.
Compiler :
Translates high-level language to assembly language.
Assembler :
Translates assembly language to machine language
(object files).
Linker :
Builds an executable file from a collection of object files.
Loader:
Reads instructions from the object file and stores them
into memory for execution.
ssues i3 $ystem $oftware
Adva3ced architectures compIicates system software
Superscalar CPU
Memory model
Multiprocessor
ew appIicatio3s
Embedded systems
Mobile computing
achi3e 3structio3s a3d programs
Instruction Set
Load and store registers
LDA, LDX, STA, STX, etc.
Integer arithmetic operations
ADD, SUB, MUL, DIV
All arithmetic operations involve register A and a word in
memory, with the result being leIt in A
COMP
Conditional iump instructions
JLT, JEQ, JGT
Subroutine linkage
JSUB, RSUB
I/O (transIerring 1 byte at a time to/Irom the rightmost 8 bits oI
register A)
Test Device instruction (TD)
Read Data (RD)
Basic AssembIer Fu3ctio3s
Session 2
3troductio3 to AssembIers
Assembler Functions:
Translating mnemonic operation codes to their machine
language equivalents.
· mnemonic code to machine code
Assigning machine addresses to symbolic labels.
· symbols to addresses
Handles
· Constants
· Literals
· Addressing
Assembly language:
A symbolic representation of machine instructions.
AssembIers.
Assembler
Linker
Loader
Source
Program
Object
Code
Executable
Code
Figure 1.2 Compilation pipeline
AssembIers.
Basic assembIer directives:
START : Starting address of the program
END : Ìndicate the end of the program
BYTE : To represent the constant
WORD : Generate one-word integer constant
RESB : Reserve the indicated number of bytes
for a data area.
RESW : Reserve the indicated number of words
for a data area.
$C AssembIer
AssembIer Fu3ctio3s:
Convert Mnemonic Operation Codes to Machine Level Equivalents.
÷ Mnemonic code (or instruction name) opcode.
Convert Symbolic Operands to their equivalent machine addresses.
(Requires Two passes).
÷ Symbolic operands (e.g., variable names) addresses.
Build the machine instructions in the proper format
Convert data constants specified in source program into their internal
machine representations.
÷ Constants Numbers.
To write Object Program and assembly listing.
$C AssembIer
$essio3 3
$C AssembIer.
ssues :
Address translation
÷ Contains forward reference
· Reference to label that is defined later in the program.
÷ Requires two passes
· label definitions and assign addresses
· actual translation (object code)
ExampIe Program with Object
Code
3e oc Source stateme3t Object code
5 1000 COPY START 1000
10 1000 FIRST STL RETADR 141033
15 1003 CLOOP JSUB RDREC 482039
20 1006 LDA LENGTH 001036
25 1009 COMP ZERO 281030
30 100C JEQ ENDFIL 301015
35 100F JSUB WRREC 482061
40 1012 J CLOOP 3C1003
45 1015 ENDFIL LDA EOF 00102A
50 1018 STA BUFFER 0C1039
55 101B LDA THREE 00102D
60 101E STA LENGTH 0C1036
65 1021 JSUB WRREC 482061
70 1024 LDL RETADR 081033
75 1027 RSUB 4C0000
80 102A EOF BYTE C'EOF' 454F46
85 102D THREE WORD 3 000003
90 1030 ZERO WORD 0 000000
95 1033 RETADR RESW 1
100 1036 LENGTH RESW 1
105 1039 BUFFER RESB 4096
110 .
115 . SUBROUTINE TO READ RECORD INTO BUFFER
Fig. 1.3 ExampIe Program
Co3td..
3e oc Source stateme3t Object co
120 .
125 2039 RDREC LDX ZERO 041030
130 203C LDA ZERO 001030
135 203F RLOOP TD INPUT E0205D
140 2042 JEQ RLOOP 30203D
145 2045 RD INPUT D8205D
150 2048 COMP ZERO 281030
155 204B JEQ EXIT 302057
160 204E STCH BUFFER,X 549039
165 2051 TIX MAXLEN 2C205E
170 2054 JLT RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A RSUB 4C0000
185 205D INPUT BYTE X'F1' F1
190 205E MAXLEN WORD 4096 001000
195 .
200 . SUBROUTINE TO WRITE RECORD FROM BUFFER
205 .
210 2061 WRREC LDX ZERO 041030
215 2064 WLOOP TD OUTPUT E02079
220 2067 JEQ WLOOP 302064
225 206A LDCH BUFFER,X 509039
230 206D WD OUTPUT DC2079
235 2070 TIX LENGTH 2C1036
240 2073 JLT WLOOP 382064
245 2076 RSUB 4C0000
250 2079 OUTPUT BYTE X'05' 05
255 END FIRST Fig. 1.4 ExampIe Program
Object code.
Purpose
÷ 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
Data transfer (RD, WD)
÷ A buffer is used to store record
÷ Buffering is necessary for different Ì/O rates
÷ The end of each record is marked with a null character (00
16
)
÷ The end of the file is indicated by a zero-length record
Subroutines (JSUB, RSUB)
÷ RDREC, WRREC
÷ Save link register first before nested jump
Object Program
The generated object code of an assembler .
The Object program format contains three types of records:
Header
Contains program name, start address and length.
Text
Contains Translated code and data of the program with
addresses (where to be loaded)
End
Specifies the end of the Object program
Address of first executable instruction
Object Program
Header record:
Col. 1 H
Col. 2-7 Program name
Col. 8-13 Starting address (hex)
Col. 14-19 Length of object program in bytes (hex)
Text record:
Col.1 T
Col.2-7 Starting address in this record (hex)
Col. 8-9 Length of object code in this record in bytes (hex)
Col. 10-69 Object code (69-10+1)/6=10 instructions
End record:
Col.1 E
Col.2-7 Address of first executable instruction (hex)
g 1.5 Object Program
Co3td.
Pass 1 (define symbols)
H COPY 001000 00107A
T 001000^1E^141033^482039^001036^281030^301015^482061 ...
T 00101E^15^0C1036^482061^081044^4C0000^454F46^000003^000000
T 002039^1E^041030^001030^E0205D^30203F^D8205D^281030
T 002057^1C^101036^4C0000^F1^001000^041030^E02079^302064
T 002073^07^382064^4C0000^05
E 001000 starting address
Fig 1.6 Object program Corresponding to Fig 1.3, Fig 1.4
Symbol used to separate fields
Co3td.
Pass 1(define symbols)
1. Assign addresses to all statements in the program
2. Save the values assigned to all labels for use in Pass 2
3. Perform some processing of assembler directives
Pass 2(assemble instructions and generate object program)
1. Assemble instructions
2. Generate data values defined by BYTE, WORD
3. Perform processing of assembler directives not done in Pass 1
4. Write the object program and the assembly listing
AssembIer AIgorithm a3d Data
$tructures
$E$$O 4
AssembIer AIgorithm a3d Data
$tructures
OPTAB (operation code table)
÷ mnemonic, machine code (instruction format, length) etc.
÷ static table
÷ instruction length
÷ array or hash table, easy for search
SYMTAB (symbol table)
÷ label name, value, flag, (type, length) etc.
÷ dynamic table (insert, delete, search)
÷ hash table, non-random keys, hashing function
Location Counter
÷ counted in bytes
Co3td.
Pass 1 Pass 2
Ìntermediate
file
Source
program
Object
code
Optab
Symtab
Symtab
AIgorithm for pass1 assembIer
Co3td.
Co3td.
Co3td.
Co3td.
AIgorithm for pass 2 AssembIer
Co3td.
AssembIer Features
$E$$O 5
AssembIer Features
Machine Dependent Assembler Features
÷ instruction formats and addressing modes
÷ program relocation
Machine Ìndependent Assembler Features
÷ literals
÷ symbol-defining statements
÷ expressions
÷ program blocks
÷ control sections and program linking
3structio3 Format a3d Addressi3g
ode
Addressing Modes:
Extended format: +op m
Ìndirect addressing: op @m
Ìmmediate addressing: op #c
Ìndex addressing: op m,X
Relative addressing: op m
3structio3 Format a3d Addressi3g
ode
START directive specifies a beginning program address of 0: a
relocatable program.
Register-to-register i3structio3s: simply convert the
mnemonic name to their number equivalents
÷ OPTAB: for opcodes
÷ SYMTAB: preloaded with register names and their values
Fetch a value stored in a register is much faster than
fetch it from the memory - Ìmproves ececution speed.
Co3td.
PC or base reIative addressi3g
÷ Calculate displacement
÷ Displacement must be small enough to fit in the 12-bit field
(-2048..2047 for PC relative mode, 0..4095 for base relative
mode)
÷ Can save one byte from using format 3 rather than format 4.
Reduce program storage space
Reduce program instruction fetch time
÷ Relocation will be easier.
Exte3ded i3structio3 format (4-byte)
÷ 20-bit field for direct addressing
Co3td.
Ìmmediate addressing mode is used whenever possible.
÷ Operand is already included in the fetched instruction.
There is no need to fetch the operand from the memory.
Ìndirect addressing mode is used whenever possible.
÷ Just one instruction rather than two is enough.
ExampIes:
ReIocatabIe programs
Starting address is 0.
Register to register i3structio3s
$impIe addressi3g
Use extended format instructions (bit e = 1).
15 0006 CLOOP +JSUB RDREC 4B101036
125 1036 RDREC CLEAR X B410
150 1049 COMPR A,S A004
5 0000 COPY START 0
Co3td.
PC-reIative
RETADR (0030) ÷ 3 = 2D.
Bits 5, 3, & = 1(set to 1).
Operand address is 0006, PC is 0001A.
Displacement is 6 ÷ 1A = ÷14 (FEC in 2's complement).
40 0017 J CLOOP 3F2FEC
10 0000 FÌRST STL RETADR 17202D
Co3td.
Base reIative:
Declare value of base register.
Address of identifier LENGTH (0033).
Directives BASE& NOBASE do not generate code.
Address of BUFFER is 0036.
Contents of BASE are 0033.
Displacement 0036- 0033= 0003.
Note: Bits x& b are 1.
12 LDB #LENGTH
13 BASE LENGTH
160 104E STCH BUFFER,X 57C003
Co3td.
mmediate addressi3g
Operand (= 3) part of instruction.
Bit = 1, indicates immediate addressing.
Operand (4096) > 12 bits.
"+¨ char indicates extended format (bit e = 1).
Directive "#¨ is address-of operator.
55 0020 LDA #3 01003
133 103C +LDT #4096 75101000
12 0003 LDB #LENGTH 69202D
Program ReIocatio3
$E$$O 7
Program ReIocatio3
AbsoIute Program :
Program with starting address specified at assembly time.
Program reIocatio3:
Programs with absolute addresses must be loaded at a specific
start3 address. so that they can be loaded and execute correctly
at any place in the memory. The address may be invalid if the
program is loaded into some where else.
%o have relocatable programs
· Assembler identifies object records that must be modified.
· Loader modifies these records.
Co3td.
eed for Program ReIocatio3:
To increase the productivity of the machine
Want to load and run several programs at the same time
(multiprogramming)
Must be able to load programs into memory wherever there is
room
Actual starting address of the program is not known until load
time
Co3td.
ExampIe :
Co3sider the foIIowi3g i3structio3s
3structio3 "+JSUB RDREC"
3structio3 "STL RETADR"
AssembIer i3serts address of RDREC relative to start of
program.
AssembIer i3structs Ioader to add program's begi33i3g
address to address of fieId i3 J$&B i3structio3 at Ioad
time.
Contd.
odificatio3 Record:
When the assembler generate an address for a symbol, the
address to be inserted into the instruction is relative to the start
of the program.
The assembler also produces a modification record, in which
the address and length of the need-to-be-modified address field
are stored.
The loader, when seeing the record, will then add the beginning
address of the loaded program to the address field stored in the
record.
Co3td.
Ìnstructions need to be modified:
The address portion of those instructions that use absolute
(direct) addresses.
Ìnstructions need not be modified:
· Ìmmediate addressing (no memory references)
· Register-to-register instructions (no memory references)
· PC or base-relative addressing (relative displacement
remains the same regardless of different starting addresses)
Co3td.
odificatio3 Record
Col. 1 M
Col. 2÷7 Starting location of the address field to be modified,
relative to the beginning of the program (hex)
Col. 8÷9 Length of the address field to be modified in half-bytes.
ampleJ$&B RDREC 3structio3
Ìnstruction "JSUB RDREC¨ assembles into 4B101036.
Starts at address 0006.
Modification record M00000705.
Load address to be added to field at relative address, 00007.
Field to be modified is 5 half-bytes long (20 bits).
Co3td.
Fig 1.6 Examples of Relocation Program
achi3e 3depe3de3t Feature
$E$$O 7
LiteraIs
LiteraI
Operand whose value appears lterally (co3sta3t) in instruction.
· Ìdentified by the prefix "=¨
'C' chars (1 per byte); 'X' hexadecimals (2 per byte).
Assembler defines constant in memory.
Operand becomes reference to this location.
iteral pools
Literals are assembled into literal pools.
LTORG creates literal pool and inserts accumulated literals.
Ensures short addresses are valid.
:plicate iterals
Assembler must recognize du5lcate literals and store only one copy of
the specified data value .
Special literals (e.., =*) must be duplicated.
LiteraI - mpIeme3tatio3
LÌTTAB
Literal name, the operand value and length, the address assigned
to the operand
Pass 1
· Build LÌTTAB with literal name, operand value and length, leaving
the address unassigned
· When LTORG statement is encountered, assign an address to
each literal not yet assigned an address
Pass 2
· search LÌTTAB for each literal operand encountered
· generate data values using BYTE or WORD statements
· generate modification record for literals that represent an address
in the program
$ymboIs
LabeIs o3 i3structio3s or data areas
EQ& irective
symbol EQU value
Creates e3try i3 symboI tabIe ($%AB) & assig3s vaIue to it.
Value may be expression involving constants and symbols
previously defined.
ORG irective
# value
Resets LOCC%R to vaIue specified.
Co3td.
amples
$impIe co3sta3ts
MAXLEN EQU 4096
. . .
+LDT #MAXLEN
Array of records
STAB RESB 1100
ORG STAB
SYMBOL RESB 6
VALUE RESB 1
FLAGS RESB 2
ORG STAB+1100
. . .
LDA VALUE,X
For an ordinary two-pass assembler, all symbols must be defined during Pass 1.
Hence, the following sequences could not be processed by an ordi3ary two-pass
assembIer.
All terms used to specify the value of the new symbol must have been defined
previously in the program.
BETA EQU ALPHA
ALPHA RESW 1
Disallowed
ORG ALPHA
BYTE1 RESB 1
BYTE2 RESB 1
BYTE3 RESB 1
ORG
ALPHA RESB 1
Disallowed
ALPHA RESW 1
BETA EQU ALPHA
Allowed
Expressio3s
Expressio3 may use co3sta3ts, user-defi3ed terms, speciaI terms.
· Location counter is one such special term.
Expressio3s ca3 be cIassified as absoIute expressio3s or reIative
expressio3s
bsol:te vs. Relative pressions
A3 absol:te expressio3 is i3depe3de3t of program Iocatio3.
· Expressions that only contain absolute terms are absolute.
· The difference of two relative terms is absolute.
· Expressions with pairs of relative terms with opposite signs are absolute.
%he absoIute expressio3 may co3tai3s reIative terms provided the reIative
terms occur i3 pairs a3d the terms i3 each such pair have opposite sig3s.
o reIative term ca3 e3ter muItipIicatio3 or divisio3 operatio3.
e.g. AXLE EQ& B&FED-B&FFER
Co3td.
A relative expressio3 depe3ds o3 program Iocatio3.
The value of a relative expression is relative to the beginning address of the object
program.
All of the relative terms except one have opposite signs.
The remaining relative term is positive.
A reIative expressio3 is o3e i3 which aII of the reIative terms except
o3e ca3 be paired as described above. %he remai3i3g u3paired term
must have a positive sig3. o reIative term ca3 e3ter muItipIicatio3 or
divisio3 operatio3.
BUFEND+BUFFER, 100-BUFFER, and 3*BUFFER are neither relative expressions
nor absolute expressions.
Expressions that are neither relative nor absolute should be flagged by the assembler as errors.
Symbol table entries must be tagged as relative or absolute.
Co3td.
ample
Co3sider some of the symboIs
RETADR RESW 1
LENGTH RESW 1
BUFFER RESB 4096
BUFEND EQU *
MAXLEN EQU BUFFEND-BUFFER
$ymboI %ype VaIue
RETADR R 0030
LENGTH R 0033
BUFFER R 0036
BUFEND R 1036
MAXLEN A 1000
Program BIocks
efinition
· Code segments that are rearranged within a single object program unit.
ontrol Sections
· Code segments that are translated into independent object program units.
&$E irective
&$E [ BIock_ame]
3dicates which portio3s of program beIo3g to various bIocks:
· Default unnamed block, or
· Named block.
&sed to reduce addressi3g probIems i3 a program.
Rearra3ged at link time or load time.
Ìf no USE statements are included, the entire program belongs
to this single block unit.
Program BIocks - mpIeme3tatio3
Pass 1
· Each program block has a separate location counter .
· Each label is assigned an address that is relative to the start of the
block that contains it .
· At the end of Pass 1, the latest value of the location counter for
each block indicates the length of that block .
· The assembIer can then assign to each block a starting address
in the object program .
Pass 2
· The address of each symbol can be computed by adding the
assigned block starting address and the relative address of the
symbol to that block .
Co3td.
Each source line is given a relative address assigned and a block
number
ample
BIock %abIe
BIock ame ame Address Le3gth
(default) 0 0000 0066
CDATA 1 0066 000B
CBLKS 2 0071 1000
Program Li3ki3g
ontrol Sections
Code segme3ts tra3sIated i3to i3depe3de3t object program u3its.
Each sectio3 ca3 be Ioaded & reIocated i3depe3de3tIy.
A sectio3 is made o3e or more reIated routi3es.
$ectio3s must be Ii3ked together to form a program.
C$EC% irective
label CSECT
Starts and names a new control section.
Exter3aI Defi3itio3 a3d Refere3ces
Exter3aI defi3itio3
EX%DEF 3ame [, 3ame]
EXTDEF names symbols that are defined in this control
section and may be used by other sections
Exter3aI refere3ce
EX%REF 3ame [,3ame]
EXTREF names symbols that are used in this control
section and are defined elsewhere
Co3td.
EX%REF irective
EXTREF symbol(,symbol)*
EXTDEF symbol(,symbol)*
ExampIe
15 0003 CLOOP +JSUB RDREC 4B100000
160 0017 +STCH BUFFER,X 57900000
190 0028 MAXLEN WORD BUFEND-BUFFER 000000
mpIeme3tatio3
The assembler must include inIormation in the obiect program that
will cause the loader to insert proper values where they are required
bject File Records
DeIine record
Col. 1 D
Col. 2-7 Name oI external symbol deIined in this control section
Col. 8-13 Relative address within this control section (hexadeccimal)
Col.14-73 Repeat inIormation in Col. 2-13 Ior other external symbols
ReIer record
Col. 1 D
Col. 2-7 Name oI external symbol reIerred to in this control section
Col. 8-73 Name oI other external reIerence symbols
Co3td.
Modification record (ew & mproved)
÷ Col. 1 M
÷ Col. 2-7 Starting address of the field to be modified (hexiadecimal)
÷ Col. 8-9 Length of the field to be modified, in half-bytes
(hexadeccimal)
÷ Col. 10 Modification flag (+ or ÷).
÷ Col.11-16 External symbol whose value is to be added to or
subtracted from the indicated field
Note: control section name is automatically an external symbol, i.e. it is
available for use in Modification records.
ssembler Desg3
Assembler Design can be done in:
Single pass
Two pass
One Pass Assembler:
Does everything in single pass
Cannot resolve the forward referencing
Co3td.
Multi pass assembler:
Does the work in two pass
Resolves the forward references
First pass:
· Scans the code
· Validates the tokens
· Creates a symbol table
Second Pass:
· Solves forward references
· Converts the code to the machine code
O3e Pass ssembler
Problems in One-pass assembler
Forward references to Data items
Forward references to labels on instructions
Solution
Require all such areas be defined before they are referenced
Labels on instructions: no good solution
Two types of one-pass assembler
Load-and-go
Produce code for immediate execution.
The other
Produce code for later execution
Load-a3d-go Assembler
Characteristics
· Useful for program development and testing
· Avoids the overhead of writing the object program out and
reading it back
· Both one-pass and two-pass assemblers can be designed
as load-and-go.
· However one-pass also avoids the over head of an
additional pass over the source program
· For a load-and-go assembIer, the actual address must be
known at assembly time, we can use an absolute program
uIti-Pass AssembIers
Restriction on EQU and ORG
· No forward reference, as symbol's value can't be defined during
the first pass .
Example:
ALPHA EQ& BE%A
BE%A EQ& DEL%A
DEL%A RE$ 1
· Assemblers with 2 passes cannot resolve .
Co3td.
Resolve forward references with as many
passes as needed
· Portions that involve forward references in symbol
definition are saved during Pass 1.
· Additional passes through stored definitions.
· Finally a normal Pass 2.
Example implementation:
· Use link lists to keep track of whose value depend
on an undefined symbol.
mpIeme3tatio3 exampIe:
icrosoft A$ AssembIer
SEGMENT
÷ a collection segments, each segment is defined as
belonging to a particular class, CODE, DATA, CONST,
STACK
÷ registers: CS (code), SS (stack), DS (data), ES, FS, GS
÷ similar to program blocks in SÌC
ASSUME
÷ e.g. ASSUME ES:DATASEG2
÷ e.g. MOVE AX, DATASEG2
MOVE ES,AX
÷ similar to BASE in SÌC
Co3td.
JUMP with forward reference
· near jump: 2 or 3 bytes
· far jump: 5 bytes
· e.g. JMP TARGET
· Warning: JMP FAR PTR TARGET
· Warning: JMP SHORT TARGET
· Pass 1: reserves 3 bytes for jump instruction
· phase error
PUBLÌC, EXTRN
· similar to EXTDEF, EXTREF in SÌC

4:780 -0.9;0 

%8.4:780,/8900,7307894:3/0789,3/90-,8.1:3.9438 41$419,70.425430398 ; 8802-078 4,/0783078  ,.74574.088478,3/425078 84/8.:8808,-4:9/083 ,3/2502039,943418802-078,3/,.74574.088479 0,2508 99033974/:.0890.43.05941'79:,2,.30 94-0.9
470390/10,9:7088:554790/ %05071472,3.041 2:,943%0.36:08070,84,3,0/ 8,570706:890 900,730784:/,;0,/84200548:7094002039,7/,9, 897:.9:708,3/8802-,3:,0

$ ! 
99003/4190.4:780 900,73078-0,-094  083,3/25020398802-078  &3/0789,3/,3/3,09010,9:708414,/078,3/3078 083,3/2502039,.74574.08847   &3/0789,3/,-4:990/083,3/4507,943841425078  3,0902502039,94341'79:,2,.30-8:554793 4-0.9 470390/5747,22310,9:708  3,0905071472,3.04102:,94390.36:08

&%!

&%

9438.9431472.9.9:708 .303897:.&39!..897:.9438 $250$8802-07 8802-07.3 %90 .8802-0781:3.98.30 /0503/0398802-0710.8.4792.28 8802-078 .3/5747..9:708  3897:.3//.3///70883 24/08 $088438 $08843 $08843 $08843 $08843 $08843 .

30 3/0503/0398802-0710.3/ !747.8. 4397480..9:708  !747.233 $088438 $08843 $08843 $08843 .9:708 ..9:708  9707.30 /0503/0398802-0710.943 ...30 3/0503/0398802-0710.8 $9.2-4.9438.9020398 57088438 . !747.439/ %90 .2#04.

9:70 .041425:907 7.&39#0.90.

8802-078 2.30 /0503/039 .&39 #0.041425:9077./8 3 /083 ..943858 -09003 88902 8419.84 57080390/ 8 .8802- 8 05.:8843 41 90 70.943 41 .3 8802-07 .3/ .3/ 2502039..8802-07 8 .9:70 %0 .70 .:880/ %0 088039. .3/ 94 5.30 3/0503/039 10.30 %8 -038 9 90 /8.30 7. 430 .88 ..8 41 .2 .0598 41 5747.43.84 /8.9.8.3/ 2.90.30/ :83 $ 2.0 3 98 :39 90 -.9:70 -0..9:708 8 .90. 708:9 98 :39 .

303897:.3/5747..28 $08843 .9438..

..70.8.90789..425:907.03.9/0890.90. .55.30$0941807..70.9:...425:907.3.7/.3974/:.70 :8:.70 $419.709415747.743203914790:8079.3/7084:7.3/.7082.70 W 70.7..908.9438419.425:907 W .98..9438419.08.94394889028419.30/0503/03.:80/-03/ :807 W 43.70/11071742 .7.7-09003:8078.2489889028419..70.3390720/.944 $89028419.90/- 90889028419..79:. .3/8003-90:807 W %0.9:70 W '79:.43889841.0730/99084:943418420574-02 :8390 .98:55479 904507..70 W $89028419.08.8..289..70 55.94341.

70 39071.0 '79:.30 39071..70 ..7/.9:..0 .$89028419...0 $8902 $419.70 . .30 39071.30 :70 %0#4041$8902$419..0 '79:. ..70 39071..

078 4.3./07 W 307  4907:9908 40.425430398  .283.70 .0 W 4.$89028419.943841-7. 0.90..38.0 .8802-07 W .3/70970.3/903 00.3:.02024785...08 7905747.774:93089.08090794:80747 8890274:9308 W $ 0/947 /0-:07  ./0807.0 :807 470390/.0$07.:90902  0 %7.947 W ..42507 W 3907570907  02472.3:.9574.

300.0 8802-07 %7.38..908 0.40.943414-0./83897:.3:.9108 307 :/8..3:.0 4-0./07 #0.8802-.94381742904-0.$89028419.8802-.-0101742.70 42507 %7.3:.908.3/894708902 3942024714700.9108 4.3:.0.38.094.:943 .:9.0942.910.30.

7!& 024724/0 :9574.0/.08847  0.3.55.425.9438   2-0//0/889028 4-0.70  /.70    $:5078.9:708....88:083$8902$419.90..425:93 .908889028419.7..

4507..303897:./..943$09 4.79209.3/.3/894707089078    $% $% 09.9438  % " % $:-74:9303. 39007.4.79209.28  3897:.47/3 20247 990708:9-030193  ! 43/943.9438.9438   $& & '  .94383.:253897:.0708907.0  $& #$& .3/5747.4507.

 97.3810773-90.9.92094.

9. # ..943 % #0./.174290792489-9841 708907  %0890.03897:.

8802-07:3.8.9438 $08843 ..

006:.3974/:.4/0  88332.705708039.398 W 907.//7088089482-4..8 W //70883 8802-..3/08 W 4389.943.4507.9438  %7.9438 .4/0942.38.0  82-4.93230243.943412.30...//708808  .3:.4/08949072.943948802-078 8802-07:3..30 .303897:.0398 W 230243.-08 W 82-4894...30.3:.

94355030 .8802-078 $4:7.9 4/0 307 0.-0 4/0 4.0 !747./07 :70 425.2 8802-07 -0.:9.

8802-07/70.9.90/3:2-0741-908 147.2 %%470570803990. . #$#0807.4389.9..90/3:2-074147/8 147...70./..39  #0307.0903/.39 #$#0807.8802-078 .08 $%#%$9..4389.909003/41905747.//708841905747.90430 47/39007.0903/./.9.70.2 3/..8.793.

9438 4389.9.3/89490706:.//708808 :/902..4389.. 507.079/.8802-893 .9438      43.398850.4507.-03.208  .20  45.06:.94383905745071472.3/.4/0 43.079$2-4.//708808  #06:708%45.07930243.30705708039.300..2.30.$8802-07 8802-07:3.239490739073...9434/0894.9 43.9433..10/384:7. 2.303897:..9!747.05747.. 507..0392.4/0 473897:.398 :2-078 %4790 -0.8808 $2-4.0398 30243.3/8 0  .7.

$8802-07 $08843 .

$8802-07 88:08 //708897.98/0130/.2 #06:708945.4/0 .38.943 4-0.943 439.38.8808 W .9073905747..883.-09.9:.97.3/.7/7010703.//708808 W .9.094.-0/0139438.0 W #010703.38147.

9 4/0 30 4.4/0                                  %# # #%# % &# $&# &%% ## #% &#   .089.                                                                 $4:7..2 .250!747.9.29 -0.250!747.902039  ! #$%  ! $%#% $% $&   ! " $&   $%  $% $&  #$& %  #  # #$ #$ #$  #%# ## % #  ##  !   &# %# % ## #%#         -0.

250!747.2 &%!&%  .9.439/ 30                              4.902039   % " #  ! " $% % % $% #$& %  # # # !&% # ! !&% # % &#   # ! %     -0.089.                                                ## # ! $4:7.4                              % !&%  $&# &%% #%# ## &# ##  !  % "   % % #$& % #$% # &%!&%  ! &#  &%!&% %  !                         .

4/0 4508902944:95:9/0.0 .47/8174235:9/0.9.-0.4/0  !:75480 #0.088.0 .9388902  .38107 #  -:11078:80/948947070.4/0  99003/419010 7908 43904:95:9/0.7147/1107039.0 903#$& 94904507..97.47/ :11073830../870..9.

90/-.074 03970.70.7.70/9.47/  $:-74:9308 $& #$& ## ## $.908 %003/410...037089071789-0147030890/:25 .3:....907  %003/41901083/.47/82. 7.

4/0.3.90/.439.9.:9.95747.38%7.//708808 07094-04.943 .38.1089003/4190 -0.9.2  //708841178900.29 .38970095084170.23.41905747.3/039 %09  439./07  439.2   %00307.9.90/4-0.21472.-03897:./0/ 3/  $50.20 89.-0.//7088.4/041.47/8 0.8802-07 %0 -0.3//.9!747.79.385747.95747.

47/3-908 0 -0.2    0.-0.47/ 4  4    !747.9.23.4/039870.47/ 0 039414-0./0770.95747.//7088 0 039414-0.9!747.9.4/0    .793.20 $9.47/ 4  4   4   4   3/70.//708839870.47/ 4  4   4   4   %0970.23-908 0 % $9.793.

:9.943 0   -0.-03897:.9!747.9438  //708841178900.2 . 3897:.

439/  !.//7088   -0.793.95747.7.88 /013082-48 $2-4:80/94805.9010/8  !     %  )) ) )  )  )  )  %  ))  ) )  ) )) ) %  ))   )   )  )  ) )   %  ))  ) ))  )   )  )   %  ) ) ) )     89.247708543/394    .

8802-07/70.90203983905747.2 $.88 !0714728420574.//70880894.90/..090.88 .904-0.95747.9438.3/90.2     .439/  !..8802-03897:.2..088341.9.:08/0130/-%  # !071472574.9.89.088341.95747.3/0307.88 790904-0.88 /013082-48    883.9438 0307.8802-893  !.8802-07/70.8830/94.9.08 8802-03897:...08349/4303!.-08147:803!.:08.

9.9:708 $$$  .3/. $97:.8802-074792.

814780.  950 039 09.30.9.943. 2.77.9. $97:.7.9:708    !% 4507.943039 .9431472.4/09.4:390/3-908 .-0 0.-0 230243... $% 82-49.9434:3907 .89.943 4.4/0 3897:.831:3.-0 .-0 343 7.9 039 09..3/.-0 38079 /0090 80. /3.-03.47.20 .2.-0 3897:.3/4208 .9. .89. 89.7.9.8802-074792.:0 1.

2 !.- !.4/0 59.88 -0.88 390720/.0 5747.439/ $4:7.- .90 10 $29.- $29.9 .

47921475,88,8802-07

439/

439/

439/

439/ .

47921475.888802-07 .

439/ .

8802-070.9:708 $$$  .

8 82-4 /013389.9020398 057088438 5747.233 .//7088324/08 5747.300503/0398802-070.9:708 3897:.8802-070.2704..943  .9438.98..9:708 907..9431472.9:708  .303/0503/0398802-070.2-4.8 .3/.3/5747.4397480.

90.9 3/70.3///70883 4/0 //708834/08      903/0/1472.//70883 #0.//70883 452 452 45.9.943472.//70883 220/.//70883 3/0.0.9. 452  452 .3897:.9.

3897:..3/907.943472.20949073:2-0706:..:9438500/ .9.0398 !%14745.9.108.208.:08  09.3.0.:089470/3.0850.9438825.9...-03335747.70890782:.07990 230243./0/97089073.917429020247 2574. 704.2.3 109..//708841 .1..3///70883 4/0   $%#%/70.080.2 #08907 94 7089073897:.89079.-05747.43.4/08 $%5704.

020392:89-082.//70883 .0 24/0 .05747.23897:.//70883 .085.0430-901742:831472..31472.0.02039 85.97.9079..8070.:.90/85.9   #0/:.9.943109.05747.439/   !47-.8070..9431472.807 903/0/3897:.9.943-00.0  #0/:.9  -90  -910/147/70..28947.024/0   147-...9.38.9.034:9419390 -910/    147!70.920 #04.

075488-0 507.075488-0 :894303897:./3.0/3897:.//7088324/08:80/030.943  %070834300/94109.3/8.439/   220/.9079.3948034: .9437.:/0/390109.//7088324/08:80/030.3/17429020247 3/70.9.90.70.904507.

.28   !$%#% $9.//70888 #08907947089073897:.-05747.//70883  ###    !# $  &800903/0/1472.93897:.9..2508 #04.9438 $250.9438 -90   ! $&##   .793.

020398   3 8.0   #$% $% #%#   #%#    985 3   80994      !  507.9.439/ ! 70.//70888  !8  85..3/.42502039 .

.9.:041-.80708907 //708841/039107%  70...4/0     $% &#    //708841&#8  439039841$.08$  $/43490307.9.70 .02039    49098 -.70  85.90.70.8070.0 % $% 0.439/ .

90.9.9 -90    %   70.90.9080903/0/1472.3/   -98 ..943 9 3/.//70883   %   507.947 ..79413897:.//70883        507.908220/.73/.//7088 414507.0  8..439/ 220/.3/  5.

!747..2#04.943 $$$  .

47/8 ..-84:90.4770.9.9 .943 -84:90!747.943 !747.8802-920 !747. 89./190 5747./0/3948420070080 %4.9./0/.!747.10/...039020247 %0.0704.-03.1.850.2  !747.../0/.3-04..:90.47/89.3/00./0724/108908070.2704.//7088 849.2#04.//7088850.28 W8802-07/0391084-0.92:89-024/10/ W4.35.990.9.2989.-05747.//70882.9.289.793..793.284.//7088082:89-04.970.

/5747.2839420247070.5747.20920 2:95747.9.439/ 00/147!747..07.2#04.941902.39944.30 .89.793.9:.-0944..223 :89-0.28349343:394.8090574/:.943   %43.0790708 7442 ./.28./ 920   .3/7:380.9908.//708841905747.70.

943.2 8-0333 .//70884110/3$&3897:.2 8802-073897:.//708841##70.250  438/079014433897:.//708894.984.09489.7941 5747.9.94.943 $&## 3897:.943 $%#%# 8802-07380798.9438 3897:.439/ ./0794.//5747./ 920 .

94370.943870.//90-0333 .79 41905747.3.47/    0390.24/1.//7088..47/ ./0/5747.7089470/ %04. 90.//7088147.//708894-0380790/394903897:.29490.84574/:.//708810/ .8802-070307.08.90.943#0.2 %0.//708810/89470/390 70.47/ 3.9.439/ 4/1.82-4 90 .0949089.47/ 903.//708841904../07 0380039070.8802-07.3/0394190300/ 94 -0 24/10/.

9.94389.2070.//708808  3897:.7/08841/110703989.9:80 .02039 702.0/85.08 !47-.9438300/94-024/10/ %0..439/  3897:.9 .0.//708808 .38908.//70883 34202477010703.793.9438 34202477010703.-84:90 /70.//7088547943 4194803897:.9438300/349-024/10/ W W W 220/.90.//70883 70.08 #08907 94 7089073897:.80 70.9.

.1 -90843  -98 .47/ 4  4  $9.9.09490-033341905747.94370.//708810/94-024/10/3.9434190.7934.250 $&##3897:.9.//7088  4/1.//0/9410/.943#0./.8802-08394   $9.2 0 4  0394190.798.9.439/ 4/1.47/   4.//708894-0.943 $&## .//7088   0/94-024/10/8.//708810/94-024/10/ 70.970.1 -908 ...0.943 3897:.

439/  ..943!747.250841#04.2 .

.9:70 $$$  ..303/0503/0390.

943 907.907.430/:5..4389.70.78907.908907.3/8947043430.9. 507.2.70..5448 % #.8 507-90 8802-07/01308./ :5.544.70.3/480.907.8 907.90907.//708808..39 33897:.:2:.3/-0..42087010703. .90/907.:0..39320247 507.094984.4541 90850.8.:0 $50...78 507-90   0./0..943 W/03910/-905701   .8 38:7088479.5448 907.10//.550...8802-0/394907.90/ .4389..8 0   2:89-0/:5.8 8802-072:8970.90907..3/380798.8.

89.//708894 0.902039803.8830/ 03% #89.7.//7088:3.3/.3.3/039 90.3/.2  !.907.3.:0.90/.4:39070/ .9705708039.3/039 0.9024/1..9. 2502039..8830/ 94904507.//7088 80.3 90.20 4507..3.907..883.47/147907.20 904507.34909.907.88 W W W .:08:83%47 #89..:0.9020398 0307.4:39070/ 0307...943  %% 907.3/03.3.//7088..94370.3.3/  !.%%1470.4507.88 W W :/%%9907.//7088 3905747.8830/.

.4:8/0130/ #70.943847/.:0949 '..3.:0 #08098 %#94.:0850.9.-0 $%  .8838.-08433897:.:02.:0 70.9.398 ..4.0 #.-0057088433.9080397382-49..0 82-4 "& .4389.70..9.3/82-48 570.10/ .$2-48 .8 "&70.

4170.439/ .47/8 $% #$  # $% $  #$  '& #$  $ #$  # $%    '&  .398 "&    % 77.2508 $250.4389.

1 90 . 82-48 2:89 -0 /0130/ /:73 !.88  03.08 .0880/ - .3 47/3.4:/ 349 -0 574.88 .0 -003 /0130/ 570.40/ # ! % #$  % #$  % #$  # ! #$  8.8802-07  90728 :80/ 94 850.7 94 5..7 94 5.:0 41 90 30 82-4 2:89 ..47 .40/ .8802-07 .3 47/3.88 .2 % "& ! !#$ %"&! ! #$  40/ 8.4:8 3 90 5747.0 90 1443 806:03.

0 057088438 -84:90.090728574.9.:735...9.-84:90 %0.9.4389.3039072:95.94347/...-84:90 W%0/110703..-84:900570884383/0503/039415747.9.784170.-84:90 W5708843895.0 907284.-84:90057088438 4770.:80.943.57088438 57088432.3-0.943.90728 W4...9..9072 57088438.9.8810/.943 W570884389.7.3/909072830.4:390784308:.09072.8.04554890838  470./0/9070.850.09072894554890838.5...9.-84:90057088432.439.943 0  "&& &# .70.0419470..398 :807 /0130/90728 850.8 #0.8:.8434507.70.0907288.057088438 3.-84:9090728..439.78.3870.3.24.

3/ &#.7-0/ .943 & &#  &# .0 05708843 8 430 3 .703090770.0347. .8802-07.703090770.-84:9084:/-01.9.943 %0..9..9.0057088438 347.943 47 /.047.439/ 70.005708843/0503/8435747.9..3 -0 5.0 .0907280.70/ 9072 2:89 .3370.24.0  70.2 419070.9.-84:90057088438 570884389.9.005708843870.9.9 5747.0 9072 .0 83 4 70..-00397082:89-09.0 %0 702.843 4507..8 /08.9.0/.-84:90 . 5489. 41 90 70.70/ .0/-90.9.9.-4.09490-0333.059 430 .0 90728 0.:041..9.70.9..870.3 03907 2:95.0907285489.059430.33 :35.04554890838 %0702.8077478 $2-49.//708841904-0.

:0       .439/ .250 438/078420419082-48 #%# % &# &  #$ #$ #$ "& "&     & &# $2-4 #%# % &# &  %50 # # # #  '.

0 &$4.8304-0.2-04394.38.20( 3/.95747.20/-4.7097.77.:9:33.5747.77.9438 W 4/080203989.8 W01.74:8-4.9.703./920 134&$89.2-0438 9498830-4..0.30/93. &80/9470/:.:39 .7070..2:39 43974$0.24.30/.20/-4.:/0/ 90039705747.//70883574-0283.5479438415747.2:398 &$70.95747.9.*.8 013943 W 4/080203989.93920474.9020398. 47 W.!747.9.2 #0.90/3943/0503/0394-0.908.

.

.

943.883940.3/. %0.793.9-4.//70889..3-0.8 2502039.:041904...88 90.9089.//7088410..439.3903.3 .24.!747.2 %0.904.4:3907 147 0.8830/.82-4..805.9.943 !.//7088 3904-0.90890039419.89. !.793.425:90/-.389 99003/41!.3/9070.-08.9-4.5747..-4.9.9.794190 -4.//70884190 82-4949.89.8830/-4..8802-07 .0949089.95747.88 W .4:3907 .7.88 W W W W .9870.2-4...-4.0.//7088.//390 .943..8....9..

439/  .70.0308.84:7..3/.250 4. 3:2-07 .0.03.:9    %    $    .9.//7088.20 //7088 039 /01.-4.8830/.%.-0 4..20 .

.

.

.

.

208.943 .38./0/ 704.30...2:398 .798./043047247070.-0$% $9.3/3.943.95747.9438 4/0802039897.3-04.!747.233 43974$0.4397480.0 ..94382:89-030/940907941472.94382.90/74:9308 $0.90/3/0503/039 80.80.5747.90/3943/0503/0394-0.2 $%70.9.

20882-489./013943 % 3.9.9438 9073.70/0130/398.9.3/#010703.20( %3.7010703.3/2.70:80/398.3/.08 9073.20 3.43974 80.20 3.0 %#3.013943.20( %#3.43974 80.70/0130/080070 .9073.-0:80/-490780.943.943.20882-489.

9.250   ! $&##    $%&#     #& &#    .0 %#82-4 82-4 %82-4 82-4 .439/ %#70.

4397480.90#0.. 4  #050.95747./0.82-47010770/94398./079438079574507.8802-072:893.943 0.47/ 4   4   .931472.0.47/ 4  4   4    .7010703.9.2502039.//70889398.47/8 013070.943 4   #0.:/031472.:80904.204109073.943 %0.70706:70/ -0.94334  147490709073.82-4/0130/398.4397480..2041490709073.:0807090.9433904-0..4397480.204109073.29.82-48 #010770.9 .082-48 .2.943 .

94370.4397480. 47 4  9073.-0147:8034/1...2.:0894-0....208.90/1742903/..2..47/ 0 2574.94370...82-4480.//7088419010/94-024/10/ 0.//0/9447 8:-97. 4   039419010/94-024/10/ 3./0.1 -908 0.439/  4/1.9.9433.793.:942.9431.47/8 .0/ 4   4   $9.82-4  0 98 ...90/10/ 490./0.. 4   4/1.309073.

33497084.888802-07   .88 ..7/7010703.090147.88 4080.88 %45.3 30!.3-0/4303   $305.079338305.8802-07083 8802-07083.

-0 $4./.82-49.4/0 '.7/7010703..9089094038 70.88 W W W $.8802-07 40890473945.079890.08147.30.3890.7/7010703.0890147.08 43.88 #084.439/ :95.88.08  7895.908.4/094902.4/0  $0.88 W W .43/!..

888802-07  !74-0283 30 5.:943 .8:.-08433897:.0894.0.0894.88.9438  $4:943 #06:70.8802-07 47.8802-07   4.4/0147.4/0147220/.88.70.3/ 4 !74/:.:943 %04907 !74/:.8-0/0130/-0147090.94383444/84:943  %4950841430 5.9000.707010703.90700./ ..30!.-08433897:.0.0/ .7/7010703.9028 47.9.7/7010703.

.9:.3/ 4  40.2/0..90789.2 .5.3 .2 47.0452039.9.95747.4/8904.8 W W W W W &801:1475747.4/8904.3/94 5.4.//70882:89-0 343./41.3:80.05747.3-0/0830/ ..8802-078./39-..//943.88.88.079084:7.-84:905747.7.84.88./41793904-0./ ./ .8802-07 90.07430 5.884.070.3/90893 ./ . 49430 5.24:9..3..4.3/ 4.84.3/ 48802-07 .8802-920 0.3/ 70..070.

33497084.:9 !.88 .94343"&..250 ! "& % % "& % % #$  W 8802-07895.888802-078 #0897..7/7010703..8808.3 9-0/0130//:73 9017895.0 .882-4 8.:0.0 .3/ # W 4147.

88 &8038989400597..708.0147.08382-4 /013943.8300/0/ W W W !4794389.88 //943.439/  #084.4.8808974:89470//0139438 3.7/7010703.!.3:3/0130/82-4  .943 W .089.82..3472.0//:73!.:0/0503/ 43.7/7010703.41480.3 5..93.8808.5.0147..2502502039.

2-4.88   %  $%  $% 7089078$ .9438020398 0.748419$8802-07  $% .7945747.250 .9.9430.794$3$ .7.40.2502039. $ $ $ 82.79.:..83$  $$& 0  $$& 0   '  ' $%$  %$ $  82.4/0 $$ 89.5... $ /..8020398/0130/.8 -043394.

7/7010703.733! $ #%%#% !.0 W W W W W W W 30.08-908147:253897:.7:2547-908 1.794% %#3$  !& %# W .439/  &!9147.7:25-908 0   ! %#% .8007747 82.943 5.733! #!%#%#% .8870807.