– do not change flags.
Unconditional jumps
Jump
• near – the target label is in the same segment than the jump • far – jump to another code segment
Direct jump jmp label
Near jump jmp Stop xor ax,ax
Stop: mov ah,4Ch
Machine code: cs:0000 cs:0002 cs:0003 cs:0005
EB 03
90
33 00
B4 4C
displacement = the difference between the target label and IP
(may also be negative) jmp Stop nop xor ax,ax
Stop: mov ah,4Ch
Assembly Languag 6/ 1
A processor executes the jump adding the displacement to the current value of IP (IP := 0002 + 3 = 0005) => IP will point to the instruction at which the program execution shall continue.
Two-pass assembler
– scans the source assembly language program twice.
The purpose of the 1st pass is to work out the locations corresponding to symbols (identifiers). To work out these locations, the assembler uses a variable known as the location counter (LC). The symbol table is created during the first pass; it records the names of variables and labels together with their attributes.
LC =
0
2
202
205
.DATA
Number DW 1234h
Array DW 100 dup(?)
Value DB 5,6,7
Symbol table:
Symbol
Segment
Offset
Type
Number
_Data
0 variable: word
Array
_Data
2 variable: word
Value
_Data
202 variable: byte
Assembly Languag 6/ 2
LC =
0
3
5
9
10
.CODE
Start:
Next:
mov mov mov dec ax,@data ds,ax cx,Number cx Symbol table:
Symbol
Segment
Offset
Type
Start
_Text
0 label: near
Next
_Text
9 label: near
Problem: forward jumps
A 16-bit displacement ∈ 〈-32768; 32767〉 is supposed, i.e. the assembler reserves two bytes for the displacement of a forward jump instruction.
In the 2nd pass the assembler uses the symbol table to generate the machine code. If the displacement is an 8-bit value ≤ 127, the second byte is filled with the op-code for instruction nop.
Operator short instructs the assembler to use an 8-bit displacement: cs:0000 EB 02 cs:0002 33 00 cs:0004 B4 4C
jmp short Stop xor ax,ax
Stop: mov ah,4Ch
Assembly Languag 6/ 3