Malaika 1
Malaika 1
Malaika 1
But in high level language, used code is translated into machine code and thus
instructions are passed to instruct the processor do the task.
Compare instruction
Conditional branch instruction
Unconditional branch instruction
Subroutines
Halting instructions
Interrupts instruction
CMP instruction:
The CMP instruction compares two operands. It is generally
used in conditional execution. This instruction basically subtracts one operand
from the other for comparing whether the operands are equal or not. It does not
disturb the destination or source operands. It is used along with the conditional
jump instruction for decision making.
Syntax:
CMP destination, source
JUMP:
Jump is an instruction to control the program flow.
JUMP
Conditional jump:
This is performed by a set of jump instructions j<condition>
depending upon the condition. The conditional instructions transfer the control
by breaking the sequential flow and they do it by changing the offset value in IP.
“Jump to label when condition occurs”.
Syntax:
Opcode label
Opcode:
Instructions Description
JE , JZ Jump if equal, Jump if zero.
Example:
.model small
.stack 100h
.data
.code
Main proc
L1:
Mov, ah, 1
Int 21h
Mov dl, 3
Cmp al,dl
JE L1
Int 21h
Main end
End main
Unconditional jump:
Control is transferred unconditionally to the target label
which points to the address of target instruction. “Jump to label without any
condition”.
Syntax:
JMP label
Example:
.model small
.stack 100h
.data
.code
Main proc
L1:
Mov ah, 2
Int 21h
Jmp L1
Mov ah 4ch
Int 21 h
Main endp
End main
Unconditional jump
Far
Short Near
JMP-Unconditional jump:
The general form of the jmp instruction is jump label.
No flags are affected by this instruction.
The short jump is a two-byte instruction that allows jumps or branches to
memory locations within +127 and -128 bytes from the address following
jump.
A near jump is three-byte instruction that allows a branch or jump within
+32 and -32 bytes (+32768B to -32768B) from the instruction in the
current code segment.
Far jump is a 5-bytes instruction that allows a jump to any memory location
within the real memory location.
Short jump:
In programming, a "short jump" is like a small leap from one point
in your code to another. It's called a "relative jump" because it doesn't go to a
fixed address; instead, it moves a certain number of steps forward or backward
from where the program currently is.
Opcode (EB): This is the command that tells the program to make a
jump.
Disp (Distance): After the opcode, there's a number that tells the
program how far to jump. This number is 8 bits long, which means it, can
represent a small distance in the code.
Opcode:
EB Disp (8 bit)
For example, if the program is at one line and you use a short jump to go 4 steps
ahead, the program will skip the next few lines and continue from the new
position.
The advantage of short jumps is that they are flexible. You can move them around
without worrying about changing the distance, making the code easier to
manage.
Near jump:
A "near jump" in programming is like making a bigger move in your
code compared to a short jump. It allows you to jump a much greater distance
forward or backward.
Distance: A near jump can move you as far as 32,768 steps forward or
backward from where you are in the code. This means it can cover a larger
part of the code compared to a short jump.
Instruction Size: The near jump instruction has 3 parts (3 bytes):
The first part is the command to "jump."
The next two parts tell the program how far to jump. These two parts
are split into a low and a high number so that the program can handle
bigger jumps.
Opcode:
E9 Disp (low) Disp (high)
Near jump
Far jump:
A "far jump" in programming is like moving to a totally different part
of the program, even in another section of memory.
- Code Segment (CS): This tells the program where the new section of code is
located.
- Instruction Pointer (IP): This shows where to start running in that new
section.
- The next four parts give the new CS and IP locations so the program knows
where to go.
Example: When a far jump happens, the program gets the new CS and IP values
from the instruction itself. This allows it to continue from a completely different
spot in memory.
Opcode:
EA IP (low) IP (high) CS (low) CS (high)
Far jump