Make your own free website on Tripod.com

Lesson 5. Logic And Arithematic Instructions.

Prev || Home || Next

bar.gif (11170 bytes)

LOGIC INSTRUCTIONS.

They are used to perform logic operations on the operators.

AND
NEG
NOT
OR
TEST
XOR

ARITHMETIC INSTRUCTIONS.

They are used to perform arithmetic operations on the operators.

ADC
ADD
DIV
IDIV
MUL
IMUL
SBB
SUB


AND INSTRUCTION
Purpose: It performs the conjunction of the operators bit by bit.

Syntax:

AND destination , source

With this instruction the "y" logic operation for both operators is carried out:

Source Destiny | Destiny
-----------------------------
1 1 | 1
1 0 | 0
0 1 | 0
0 0 | 0

The result of this operation is stored on the destiny operator.
NEG INSTRUCTION
Purpose: It generates the complement to 2.

Syntax:

NEG destiny

This instruction generates the complement to 2 of the destiny operator and
stores it on the same operator. For example, if AX stores the value of 1234H,
then:

NEG AX

This would leave the EDCCH value stored on the AX register.

NOT INSTRUCTION
Purpose: It carries out the negation of the destiny operator bit by bit.

Syntax:

NOT destiny

The result is stored on the same destiny operator.

OR INSTRUCTION
Purpose: Logic inclusive OR

Syntax:

OR destination , source



The OR instruction carries out, bit by bit, the logic inclusive disjunction of
the two operators:
Source Destiny | Destiny
-----------------------------------
1 1 | 1
1 0 | 1
0 1 | 1
0 0 | 0


TEST INSTRUCTION
Purpose: It logically compares the operators

Syntax:

TEST destination , source

It performs a conjunction, bit by bit, of the operators, but differing from AND,
this instruction does not place the result on the destiny operator, it only has
effect on the state of the flags.

XOR INSTRUCTION
Purpose: OR exclusive


Syntax:

XOR destination , source Its function is to perform the logic exclusive disjunction of
the two operators bit by bit.
Source Destiny | Destiny
-----------------------------------
1 1 | 0
0 0 | 1
0 1 | 1
0 0 | 0


ADC INSTRUCTION
Purpose: Cartage addition

Syntax:

ADC destination , source

It carries out the addition of two operators and adds one to the result in case
the CF flag is activated, this is in case there is catage.

The result is stored on the destiny operator.


ADD INSTRUCTION
Purpose: Addition of the operators.

Syntax:

ADD destination , source

It adds the two operators and stores the result on the destiny operator.

DIV INSTRUCTION
Purpose: Division without sign.

Syntax:

DIV source

The divider can be a byte or a word and it is the operator which is given the
instruction.

If the divider is 8 bits, the 16 bits AX register is taken as dividend and if the
divider is 16 bits the even DX:AX register will be taken as dividend, taking the
DX high word and AX as the low.

If the divider was a byte then the quotient will be stored on the AL register
and the residue on AH, if it was a word then the quotient is stored on AX and
the residue on DX.


IDIV INSTRUCTION
Purpose: Division with sign.

Syntax:

IDIV source

It basically consists on the same as the DIV instruction, and the only
difference is that this one performs the operation with sign.

For its results it used the same registers as the DIV instruction.

MUL INSTRUCTION
Purpose: Multiplication with sign.

Syntax:

MUL source

The assembler assumes that the multiplicand will be of the same size as the
multiplier, therefore it multiplies the value stored on the register given as
operator by the one found to be contained in AH if the multiplier is 8 bits or
by AX if the multiplier is 16 bits.

When a multiplication is done with 8 bit values, the result is stored on the AX
register and when the multiplication is with 16 bit values the result is stored
on the even DX:AX register.

IMUL INSTRUCTION
Purpose: Multiplication of two whole numbers with sign.

Syntax:

IMUL source

This command does the same as the one before, only that this one does take into account the signs of the numbers being
multiplied.

The results are kept in the same registers that the MOV instruction uses.

SBB INSTRUCTION
Purpose: Subtraction with cartage.

Syntax:

SBB destination , source

This instruction subtracts the operators and subtracts one to the result if CF
is activated. The source operator is always subtracted from the destiny.

This kind of subtraction is used when one is working with 32 bits quantities.


SUB INSTRUCTION
Purpose: Subtraction.

Syntax:

SUB destination , source

It subtracts the source operator from the destiny.

PROCESS CONTROL INSTRUCTIONS
JUMP INSTRUCTIONS
They are used to transfer the flow of the process to the indicated operator.

JMP
JA (JNBE)
JAE (JNBE)
JB (JNAE)
JBE (JNA)
JE (JZ)
JNE (JNZ)
JG (JNLE)
JGE (JNL)
JL (JNGE)
JLE (JNG)
JC
JNC
JNO
JNP (JPO)
JNS
JO
JP (JPE)
JS

INSTRUCTIONS FOR CYCLES: LOOP

They transfer the process flow, conditionally or unconditionally, to a destiny,
repeating this action until the counter is zero.

LOOP
LOOPE
LOOPNE

COUNTING INSTRUCTIONS

They are used to decrease or increase the content of the counters.

DEC
INC

COMPARISON INSTRUCTIONS

They are used to compare operators, and they affect the content of the flags.

CMP
CMPS (CMPSB) (CMPSW)

FLAG INSTRUCTIONS

They directly affect the content of the flags.

CLS
CLD
CLI
CMC
STC
STD
STI

JMP INSTRUCTION
Purpose: Unconditional jump.

Syntax:

JMP destiny

This instruction is used to deviate the flow of a program without taking into
account the actual conditions of the flags or of the data.

JA (JNBE) INSTRUCTION
Purpose: Conditional jump.

Syntax:

JA Label
After a comparison this command jumps if it is up or jumps if it is not down or
if not it is the equal.

This means that the jump is only done if the CF flag is deactivated or if the ZF
flag is deactivated, that is that one of the two be equal to zero.

JAE (JNB) INSTRUCTION
Purpose: Conditional jump.

Syntax:

JAE label
It jumps if it is up or it is the equal or if it is not down.

The jump is done if CF is deactivated.

JB (JNAE) INSTRUCTION
Purpose: Conditional jump.

Syntax:

JB label
It jumps if it is down, if it is not up, or if it is the equal.

The jump is done if CF is activated.


JBE (JNA) INSTRUCTION
Purpose: Conditional jump.

Syntax:

JBE label
It jumps if it is down, the equal, or if it is not up.

The jump is done if CF is activated or if ZF is activated, that any of them be
equal to 1.

JE (JZ) INSTRUCTION
Purpose: Conditional jump.

Syntax:

JE label
It jumps if it is the equal or if it is zero.

The jump is done if ZF is activated.


JNE (JNZ) INSTRUCTION
Purpose: Conditional jump.

Syntax:

JNE label
It jumps if it is not equal or zero.

The jump will be done if ZF is deactivated.

JG (JNLE) INSTRUCTION
Purpose: Conditional jump, and the sign is taken into account.

Syntax:

JG label
It jumps if it is larger, if it is not larger or equal.

The jump occurs if ZF = 0 or if OF = SF.
JGE (JNL) INSTRUCTION
Purpose: Conditional jump, and the sign is taken into account.

Syntax:

JGE label
It jumps if it is larger or less than, or equal to.

The jump is done if SF = OF

JL (JNGE) INSTRUCTION
Purpose: Conditional jump, and the sign is taken into account.

Syntax:

JL label
It jumps if it is less than or if it is not larger than or equal to.

The jump is done if SF is different than OF.
JLE (JNG) INSTRUCTION
Purpose: Conditional jump, and the sign is taken into account.

Syntax:

JLE label
It jumps if it is less than or equal to, or if it is not larger.

The jump is done if ZF = 1 or if SF is different than OF.

JC INSTRUCTION
Purpose: Conditional jump, and the flags are taken into account.

Syntax:

JC label
It jumps if there is cartage.

The jump is done if CF = 1
JNC INSTRUCTION
Purpose: Conditional jump, and the state of the flags is taken into account.

Syntax:

JNC label
It jumps if there is no cartage.

The jump is done if CF = 0.

JNO INSTRUCTION
Purpose: Conditional jump, and the state of the flags is taken into account.

Syntax:

JNO label
It jumps if there is no overflow.

The jump is done if OF = 0.
JNP (JPO) INSTRUCTION
Purpose: Conditional jump, and the state of the flags is taken into account.

Syntax:

JNP label
It jumps if there is no parity or if the parity is uneven.

The jump is done if PF = 0.

JNS INSTRUCTION
Purpose: Conditional jump, and the state of the flags is taken into account.

Syntax:

JNP label
It jumps if the sign is deactivated.

The jump is done if SF = 0.
JO INSTRUCTION
Purpose: Conditional jump, and the state of the flags is taken into account.

Syntax:

JO label
It jumps if there is overflow.

The jump is done if OF = 1.

JP (JPE) INSTRUCTION
Purpose: Conditional jump, the state of the flags is taken into account.

Syntax:

JP label
It jumps if there is parity or if the parity is even.

The jump is done if PF = 1.
JS INSTRUCTION
Purpose: Conditional jump, and the state of the flags is taken into account.

Syntax:

JS label
It jumps if the sign is on.

The jump is done if SF = 1.

bar.gif (11170 bytes)

Prev || Home || Next