Saint Louis University School of Engineering and Architecture Department of Electrical Engineering
Saint Louis University School of Engineering and Architecture Department of Electrical Engineering
Saint Louis University School of Engineering and Architecture Department of Electrical Engineering
Jump Instructions
Let’s assume that the variables are stored in the following registers:
Register Content
$0 f
$1 g
$2 h
$3 i
$4 j
In these types of instructions, the processor must check for the particular
condition. If it is true, then only the jump takes place else the normal flow in
the execution of the statements is maintained.
The ALU operations set flags in the status word (Flag register). The
conditional jump statements tests the flag and jump is the flag is set.
If you emulate this code you will see that all instructions are assembled
into JNB, the operational code (opcode) for this instruction is 73h this
instruction has fixed length of two bytes, the second byte is number of bytes
to add to the IP register if the condition is true. because the instruction has
only 1 byte to keep the offset it is limited to pass control to -128 bytes back or
127 bytes forward, this value is always signed.
jnc a
jnb a
jae a
mov ax, 4
a: mov ax, 5
ret
Generally, when it is required to compare numeric
values CMP instruction is used (it does the same as SUB (subtract)
instruction, but does not keep the result, just affects the flags).
Another example:
it's required to compare 7 and 7,
7-7=0
the result is zero! (Zero Flag is set to 1 and JZ or JE will do the jump).
include "emu8086.inc"
org 100h
stop:
org 100h
mov cx, 5
k1: add bx, 1
mov al, '1'
mov ah, 0eh
int 10h
push cx
mov cx, 5
k2: add bx, 1
mov al, '2'
mov ah, 0eh
int 10h
push cx
mov cx, 5
k3: add bx, 1
mov al, '3'
mov ah, 0eh
int 10h
loop k3 ; internal in internal loop.
pop cx
loop k2 ; internal loop.
pop cx
loop k1 ; external loop.
ret
bx counts total number of steps, by default emulator shows values in
hexadecimal, you can double click the register to see the value in all
available bases.
Just like all other conditional jumps loops have an opposite companion that
can help to create workarounds, when the address of desired location is
too far assemble automatically assembles reverse and long jump
instruction, making total of 5 bytes instead of just 2, it can be seen in
disassembler as well.
References: https://jbwyatt.com/253/emu/asm_tutorial_07.html
https://www.includehelp.com/embedded-system/jump-
instructions-in-8086- microprocessor.aspx
http://eceweb.ucsd.edu/~gert/ece30/CN2.pdf