BSCS

Jump instructions

Jump instructions– do not change flags.

  1. Jump Instructions – The jump instruction transfers the program sequence to the memory address given in the operand based on the specified flag. …
  2. Call Instructions – The call instruction transfers the program sequence to the memory address given in the operand.

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

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.

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.

Far jump

The machine code operand of far jump is the complete
address of the destination in the order: offset, segment (4
bytes). A processor executes the jump loading IP by the offset
and CS by the segment.
If the forward jump is a far jump, we must instruct the
assembler to reserve 4 bytes for the operand by defining the
far type label:
jmp far ptr StopInAnotherSegment

Leave a Reply

Your email address will not be published. Required fields are marked *