Chapter2 Notes
Chapter2 Notes
1. Introduction
2. Basic Concepts
3. Assembler programming
4. Assembler language instructions
5. Interruptions and file managing
6. Macros and procedures
7. Program examples
1. Introduction
Table of contents
1.2 Presentation
The document you are looking at, has the primordial function of introducing you to
assembly language programming, and it has been thought for those people who have
never worked with this language.
The tutorial is completely focused towards the computers that function with processors of
the x86 family of Intel, and considering that the language bases its functioning on the
internal resources of the processor, the described examples are not compatible with any
other architecture.
The information was structured in units in order to allow easy access to each of the topics
and facilitate the following of the tutorial.
In the introductory section some of the elemental concepts regarding computer systems
are mentioned, along with the concepts of the assembly language itself, and continues
with the tutorial itself.
The second reason is the total control of the PC which you can have with the use of the
assembler.
Another reason is that the assembly programs are quicker, smaller, and have larger
capacities than ones created with other languages.
2. Basic Concepts
Table of Contents
Computer System.
This part is also known as central processing unit or CPU, which in turn is made by the
control unit and the arithmetic and logic unit. Its functions consist in reading and writing
the contents of the memory cells, to forward data between memory cells and special
registers, and decode and execute the instructions of a program. The processor has a
series of memory cells which are used very often and thus, are part of the CPU. These
cells are known with the name of registers. A processor may have one or two dozen of
these registers. The arithmetic and logic unit of the CPU realizes the operations related
with numeric and symbolic calculations. Typically these units only have capacity of
performing very elemental operations such as: the addition and subtraction of two whole
numbers, whole number multiplication and division, handling of the registers' bits and the
comparison of the content of two registers. Personal computers can be classified by what
is known as word size, this is, the quantity of bits which the processor can handle at a
time.
It is a group of cells, now being fabricated with semi-conductors, used for general
processes, such as the execution of programs and the storage of information for the
operations.
Each one of these cells may contain a numeric value and they have the property of being
addressable, this is, that they can distinguish one from another by means of a unique
number or an address for each cell.
The generic name of these memories is Random Access Memory or RAM. The main
disadvantage of this type of memory is that the integrated circuits lose the information
they have stored when the electricity flow is interrupted. This was the reason for the
creation of memories whose information is not lost when the system is turned off. These
memories receive the name of Read Only Memory or ROM.
Some of the most common input units are keyboards and mice. The most common output
units are screens and printers.
Since the central memory of a computer is costly, and considering today's applications it
is also very limited. Thus, the need to create practical and economical information
storage systems arises. Besides, the central memory loses its content when the machine is
turned off, therefore making it inconvenient for the permanent storage of data.
These and other inconvenience give place for the creation of peripheral units of memory
which receive the name of auxiliary or secondary memory. Of these the most common
are the tapes and magnetic discs.
The stored information on these magnetic media means receive the name of files. A file is
made of a variable number of registers, generally of a fixed size; the registers may
contain information or programs.
A flip-flop is a device capable of storing two levels of voltage, a low one, regularly 0.5
volts, and another one, commonly of 5 volts. The low level of energy in the flip-flop is
interpreted as off or 0, and the high level as on or 1. These states are usually known as
bits, which are the smallest information unit in a computer.
A group of 16 bits is known as word; a word can be divided in groups of 8 bits called
bytes, and the groups of 4 bits are called nibbles.
The numeric system we use daily is the decimal system, but this system is not convenient
for machines since the information is handled codified in the shape of on or off bits; this
way of codifying takes us to the necessity of knowing the positional calculation which
will allow us to express a number in any base where we need it.
Where n is the position of the digit beginning from right to left and numbering from zero.
D is the digit on which we operate and B is the used numeric base.
When working with assembly language we come on the necessity of converting numbers
from the binary system, which is used by computers, to the decimal system used by
people.
The binary system is based on only two conditions or states, be it on(1) or off(0), thus its
base is two.
For example, if we have the binary number of 10011, we take each digit from right to left
and multiply it by the base, elevated to the new position they are:
The ^ character is used in computation as an exponent symbol and the * character is used
to represent multiplication.
There are several methods to convert decimal numbers to binary; only one will be
analyzed here. Naturally a conversion with a scientific calculator is much easier, but one
cannot always count with one, so it is convenient to at least know one formula to do it.
The method that will be explained uses the successive division of two, keeping the
residue as a binary digit and the result as the next number to divide.
Let us take for example the decimal number of 43.
Building the number from the bottom , we get that the binary result is 101011
On the hexadecimal base we have 16 digits which go from 0 to 9 and from the letter A to
the F, these letters represent the numbers from 10 to 15. Thus we count
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, and F.
The conversion between binary and hexadecimal numbers is easy. The first thing done to
do a conversion of a binary number to a hexadecimal is to divide it in groups of 4 bits,
beginning from the right to the left. In case the last group, the one most to the left, is
under 4 bits, the missing places are filled with zeros.
Taking as an example the binary number of 101011, we divide it in 4 bits groups and we
are left with:
10;1011
Filling the last group with zeros (the one from the left):
0010;1011
Afterwards we take each group as an independent number and we consider its decimal
value:
0010=2;1011=11
But since we cannot represent this hexadecimal number as 211 because it would be an
error, we have to substitute all the values greater than 9 by their respective representation
in hexadecimal, with which we obtain:
2BH
where the H represents the hexadecimal base.
[Link].ASCII code
[Link] BCD method
[Link] Floating point representation
ASCII is an acronym of American Standard Code for Information Interchange. This code
assigns the letters of the alphabet, decimal digits from 0 to 9 and some additional symbols
a binary number of 7 bits, putting the 8th bit in its off state or 0. This way each letter,
digit or special character occupies one byte in the computer memory.
We can observe that this method of data representation is very inefficient on the numeric
aspect, since in binary format one byte is not enough to represent numbers from 0 to 255,
but on the other hand with the ASCII code one byte may represent only one digit. Due to
this inefficiency, the ASCII code is mainly used in the memory to represent text.
BCD is an acronym of Binary Coded Decimal. In this notation groups of 4 bits are used
to represent each decimal digit from 0 to 9. With this method we can represent two digits
per byte of information.
Even when this method is much more practical for number representation in the memory
compared to the ASCII code, it still less practical than the binary since with the BCD
method we can only represent digits from 0 to 99. On the other hand in binary format we
can represent all digits from 0 to 255.
This format is mainly used to represent very large numbers in mercantile applications
since it facilitates operations avoiding mistakes.
This representation is based on scientific notation, this is, to represent a number in two
parts: its base and its exponent.
Design of the algorithm, stage the problem to be solved is established and the
best solution is proposed, creating squematic diagrams used for the better solution
proposal.
Coding the algorithm, consists in writing the program in some programming
language; assembly language in this specific case, taking as a base the proposed
solution on the prior step.
Translation to machine language, is the creation of the object program, in other
words, the written program as a sequence of zeros and ones that can be interpreted
by the processor.
Test the program, after the translation the program into machine language,
execute the program in the computer machine.
The last stage is the elimination of detected faults on the program on the test
stage. The correction of a fault normally requires the repetition of all the steps
from the first or second.
The CPU has 4 internal registers, each one of 16 bits. The first four, AX, BX, CX, and
DX are general use registers and can also be used as 8 bit registers, if used in such a way
it is necessary to refer to them for example as: AH and AL, which are the high and low
bytes of the AX register. This nomenclature is also applicable to the BX, CX, and DX
registers.
To create a program in assembler two options exist, the first one is to use the TASM or
Turbo Assembler, of Borland, and the second one is to use the debugger - on this first
section we will use this last one since it is found in any PC with the MS-DOS, which
makes it available to any user who has access to a machine with these characteristics.
Debug can only create files with a .COM extension, and because of the characteristics of
these kinds of programs they cannot be larger that 64 kb, and they also must start with
displacement, offset, or 0100H memory direction inside the specific segment.
Debug provides a set of commands that lets you perform a number of useful operations:
It is possible to visualize the values of the internal registers of the CPU using the Debug
program. To begin working with Debug, type the following prompt in your computer:
C:/>Debug [Enter]
On the next line a dash will appear, this is the indicator of Debug, at this moment the
instructions of Debug can be introduced using the following command:
All the contents of the internal registers of the CPU are displayed; an alternative of
viewing them is to use the "r" command using as a parameter the name of the register
whose value wants to be seen. For example:
-rbx BX 0000 :
This instruction will only display the content of the BX register and the Debug indicator
changes from "-" to ":"
When the prompt is like this, it is possible to change the value of the register which was
seen by typing the new value and [Enter], or the old value can be left by pressing [Enter]
without typing any other value.
2.3.4 Assembler structure
In assembly language code lines have two parts, the first one is the name of the
instruction which is to be executed, and the second one are the parameters of the
command. For example:
add ah bh
Here "add" is the command to be executed, in this case an addition, and "ah" as well as
"bh" are the parameters.
For example:
mov al, 25
In the above example, we are using the instruction mov, it means move the value 25 to al
register.
The name of the instructions in this language is made of two, three or four letters. These
instructions are also called mnemonic names or operation codes, since they represent a
function the processor will perform.
add al,[170]
The brackets in the second parameter indicate to us that we are going to work with the
content of the memory cell number 170 and not with the 170 value, this is known as
direct addressing.
The first step is to initiate the Debug, this step only consists of typing debug[Enter] on
the operative system prompt.
To assemble a program on the Debug, the "a" (assemble) command is used; when this
command is used, the address where you want the assembling to begin can be given as a
parameter, if the parameter is omitted the assembling will be initiated at the locality
specified by CS:IP, usually 0100h, which is the locality where programs with .COM
extension must be initiated. And it will be the place we will use since only Debug can
create this specific type of programs.
Even though at this moment it is not necessary to give the "a" command a parameter, it is
recommendable to do so to avoid problems once the CS:IP registers are used, therefore
we type:
a 100[enter] mov ax,0002[enter] mov bx,0004[enter] add ax,bx[enter]
nop[enter][enter]
What does the program do?, move the value 0002 to the ax register, move the value 0004
to the bx register, add the contents of the ax and bx registers, the instruction, no
operation, to finish the program.
In the debug program. After to do this, appear on the screen some like the follow lines:
Type the command "t" (trace), to execute each instruction of this program, example:
You see that the value 2 move to AX register. Type the command "t" (trace), again, and
you see the second instruction is executed.
Type the command "t" (trace) to see the instruction add is executed, you will see the
follow lines:
The possibility that the registers contain different values exists, but AX and BX must be
the same, since they are the ones we just modified.
It would not seem practical to type an entire program each time it is needed, and to avoid
this it is possible to store a program on the disk, with the enormous advantage that by
being already assembled it will not be necessary to run Debug again to execute it.
Obtain the length of the program subtracting the final address from the initial
address, naturally in hexadecimal system.
Give the program a name and extension.
Put the length of the program on the CX register.
Order Debug to write the program on the disk.
By using as an example the following program, we will have a clearer idea of how to take
these steps:
To obtain the length of a program the "h" command is used, since it will show us the
addition and subtraction of two numbers in hexadecimal. To obtain the length of ours, we
give it as parameters the value of our program's final address (10A), and the program's
initial address (100). The first result the command shows us is the addition of the
parameters and the second is the subtraction.
-n [Link]
The "rcx" command allows us to change the content of the CX register to the value we
obtained from the size of the file with "h", in this case 000a, since the result of the
subtraction of the final address from the initial address.
Lastly, the "w" command writes our program on the disk, indicating how many bytes it
wrote.
To obtain the correct result of the following steps, it is necessary that the above program
be already created.
Debug always loads the programs on memory on the address 100H, otherwise indicated.
3. Assembler programming
Table of Contents
First an editor to create the source program. Second a compiler, which is nothing more
than a program that "translates" the source program into an object program. And third, a
linker that generates the executable program from the object program.
The editor can be any text editor at hand, and as a compiler we will use the TASM macro
assembler from Borland, and as a linker we will use the Tlink program.
The extension used so that TASM recognizes the source programs in assembler is .ASM;
once translated the source program, the TASM creates a file with the .OBJ extension, this
file contains an "intermediate format" of the program, called like this because it is not
executable yet but it is not a program in source language either anymore. The linker
generates, from a .OBJ or a combination of several of these files, an executable program,
whose extension usually is .EXE though it can also be .COM, depending of the form it
was assembled.
To build assembler programs using TASM programs is a different program structure than
from using debug program.
It's important to include the following assembler directives:
.MODEL SMALL
Assembler directive that defines the memory model to use in the program
.CODE
Assembler directive that defines the program instructions
.STACK
Assembler directive that reserves a memory space for program instructions in the stack
END
Assembler directive that finishes the assembler program
Let's program
First step
use any editor program to create the source file. Type the following lines:
first example
Second step
Save the file with the following name: [Link]. Don't forget to save this in ASCII
format.
Third step
Example:
Fourth step
Where [Link] is the name of the intermediate program, .OBJ. This generates a file
directly with the name of the intermediate program and the .EXE extension.
Fifth step
C:\>exam1[enter]
Assembly process.
Segments
Table of symbols
SEGMENTS
The architecture of the x86 processors forces to the use of memory segments to manage
the information, the size of these segments is of 64kb.
The reason of being of these segments is that, considering that the maximum size of a
number that the processor can manage is given by a word of 16 bits or register, it would
not be possible to access more than 65536 localities of memory using only one of these
registers, but now, if the PC's memory is divided into groups or segments, each one of
65536 localities, and we use an address on an exclusive register to find each segment, and
then we make each address of a specific slot with two registers, it is possible for us to
access a quantity of 4294967296 bytes of memory, which is, in the present day, more
memory than what we will see installed in a PC.
In order for the assembler to be able to manage the data, it is necessary that each piece of
information or instruction be found in the area that corresponds to its respective
segments. The assembler accesses this information taking into account the localization of
the segment, given by the DS, ES, SS and CS registers and inside the register the address
of the specified piece of information. It is because of this that when we create a program
using the Debug on each line that we assemble, something like this appears:
1CB0:0102 MOV AX,BX
Where the first number, 1CB0, corresponds to the memory segment being used, the
second one refers to the address inside this segment, and the instructions which will be
stored from that address follow.
The way to indicate to the assembler with which of the segments we will work with is
with the .CODE, .DATA and .STACK directives.
The assembler adjusts the size of the segments taking as a base the number of bytes each
assembled instruction needs, since it would be a waste of memory to use the whole
segments. For example, if a program only needs 10kb to store data, the data segment will
only be of 10kb and not the 64kb it can handle.
SYMBOLS CHART
Each one of the parts on code line in assembler is known as token, for example on the
code line:
MOV AX,Var
we have three tokens, the MOV instruction, the AX operator, and the VAR operator.
What the assembler does to generate the OBJ code is to read each one of the tokens and
look for it on an internal "equivalence" chart known as the reserved words chart, which is
where all the mnemonic meanings we use as instructions are found.
Following this process, the assembler reads MOV, looks for it on its chart and identifies
it as a processor instruction. Likewise it reads AX and recognizes it as a register of the
processor, but when it looks for the Var token on the reserved words chart, it does not
find it, so then it looks for it on the symbols chart which is a table where the names of the
variables, constants and labels used in the program where their addresses on memory are
included and the sort of data it contains, are found.
Sometimes the assembler comes on a token which is not defined on the program,
therefore what it does in these cased is to pass a second time by the source program to
verify all references to that symbol and place it on the symbols chart.
There are symbols which the assembler will not find since they do not belong to that
segment and the program does not know in what part of the memory it will find that
segment, and at this time the linker comes into action, which will create the structur
first step
use any editor program to create the source file. Type the following lines:
;example11 .model small .stack .code mov ah,2h ;moves the value 2h to
register ah mov dl,2ah ;moves de value 2ah to register dl ;(Its the
asterisk value in ASCII format) int 21h ;21h interruption mov
ah,4ch ;4ch function, goes to operating system int 21h ;21h interruption
end ;finishes the program code
second step
Save the file with the following name: [Link]. Don't forget to save this in ASCII
format.
third step
fourth step
fifth step
C:\>ejem11[enter] * C:\>
This assembler program shows the asterisk character on the computer screen
In any program it is necessary to move the data in the memory and in the CPU registers;
there are several ways to do this: it can copy data in the memory to some register, from
register to register, from a register to a stack, from a stack to a register, to transmit data to
external devices as well as vice versa.
This movement of data is subject to rules and restrictions. The following are some of
them:
It is possible to move data blocks by means of the movs instructions, which copies a
chain of bytes or words; movsb which copies n bytes from a locality to another; and
movsw copies n words from a locality to another. The last two instructions take the
values from the defined addresses by DS:SI as a group of data to move and ES:DI as the
new localization of the data.
To move data there are also structures called batteries, where the data is introduced with
the push instruction and are extracted with the pop instruction.
In a stack the first data to be introduced is the last one we can take, this is, if in our
program we use these instructions:
To return the correct values to each register at the moment of taking them from the stack
it is necessary to do it in the following order:
For the communication with external devices the out command is used to send
information to a port and the in command to read the information received from a port.
OUT DX,AX
Where DX contains the value of the port which will be used for the communication and
AX contains the information which will be sent.
IN AX,DX
Where AX is the register where the incoming information will be kept and DX contains
the address of the port by which the information will arrive.
Almost all the comparison instructions are based on the information contained in the flag
register. Normally the flags of this register which can be directly handled by the
programmer are the data direction flag DF, used to define the operations about chains.
Another one which can also be handled is the IF flag by means of the sti and cli
instructions, to activate and deactivate the interruptions.
The unconditional jumps in a written program in assembler language are given by the
jmp instruction; a jump is to moves the flow of the execution of a program by sending the
control to the indicated address.
A loop, known also as iteration, is the repetition of a process a certain number of times
until a condition is fulfilled. These loops are used
MOV
MOVS (MOVSB) (MOVSW)
MOV Instruction
Purpose: Data transfer between memory cells, registers and the accumulator.
Syntax:
Where Destiny is the place where the data will be moved and Source is the place where
the data is.
Example:
This small program moves the value of 0006H to the AX register, then it moves the
content of AX (0006h) to the BX register, and lastly it moves the 4C00h value to the AX
register to end the execution with the 4C option of the 21h interruption.
Purpose: To move byte or word chains from the source, addressed by SI, to the destiny
addressed by DI.
Syntax:
MOVS
This command does not need parameters since it takes as source address the content of
the SI register and as destination the content of DI. The following sequence of
instructions illustrates this:
First we initialize the values of SI and DI with the addresses of the VAR1 and VAR2
variables respectively, then after executing MOVS the content of VAR1 is copied onto
VAR2.
The MOVSB and MOVSW are used in the same way as MOVS, the first one moves one
byte and the second one moves a word.
4.2 Loading instructions
They are specific register instructions. They are used to load bytes or chains of bytes onto
a register.
Syntax:
LODS
This instruction takes the chain found on the address specified by SI, loads it to the AL
(or AX) register and adds or subtracts , depending on the state of DF, to SI if it is a bytes
transfer or if it is a words transfer.
The first line loads the VAR1 address on SI and the second line takes the content of that
locality to the AL register.
The LODSB and LODSW commands are used in the same way, the first one loads a byte
and the second one a word (it uses the complete AX register).
LAHF Instruction
Syntax:
LAHF
This instruction is useful to verify the state of the flags during the execution of our
program.
The flags are left in the following order inside the register:
SF ZF ?? AF ?? PF ?? CF
The "??" means that there will be an undefined value in those bits.
LDS Instruction
Syntax:
The source operator must be a double word in memory. The word associated with the
largest address is transferred to DS, in other words it is taken as the segment address. The
word associated with the smaller address is the displacement address and it is deposited
in the register indicated as destiny.
LEA Instruction
Syntax:
The source operator must be located in memory, and its displacement is placed on the
index register or specified pointer in destiny.
To illustrate one of the facilities we have with this command let us write an equivalence:
Is equivalent to:
LEA SI,VAR1
It is very probable that for the programmer it is much easier to create extensive programs
by using this last format.
LES Instruction
Syntax:
The source operator must be a double word operator in memory. The content of the word
with the larger address is interpreted as the segment address and it is placed in ES. The
word with the smaller address is the displacement address and it is placed in the specified
register on the destiny parameter.
POP
POPF
PUSH
PUSHF
POP Instruction
Syntax:
POP destiny
This instruction transfers the last value stored on the stack to the destiny operator, it then
increases by 2 the SP register.
This increase is due to the fact that the stack grows from the highest memory segment
address to the lowest, and the stack only works with words, 2 bytes, so then by increasing
by two the SP register, in reality two are being subtracted from the real size of the stack.
POPF Instruction
Syntax:
POPF
This command transfers bits of the word stored on the higher part of the stack to the flag
register.
BIT FLAG
0 CF
2 PF
4 AF
6 ZF
7 SF
8 TF
9 IF
10 DF
11 OF
Once the transference is done the SP register is increased by 2, diminishing the size of the
stack.
PUSH Instruction
Syntax:
PUSH source
The PUSH instruction decreases by two the value of SP and then transfers the content of
the source operator to the new resulting address on the recently modified register.
The decrease on the address is due to the fact that when adding values to the stack, this
one grows from the greater to the smaller segment address, therefore by subtracting 2
from the SP register what we do is to increase the size of the stack by two bytes, which is
the only quantity of information the stack can handle on each input and output of
information.
PUSHF Instruction
Syntax:
PUSHF
This command decreases by 2 the value of the SP register and then the content of the flag
register is transferred to the stack, on the address indicated by SP.
The flags are left stored in memory on the same bits indicated on the POPF command.
AND
NEG
NOT
OR
TEST
XOR
AND Instruction
Syntax:
With this instruction the "y" logic operation for both operators is carried out:
NEG Instruction
Syntax:
NEG destiny
This instruction generates the complement to 2 of the destiny operator and stores it on the
same operator.
NEG AX
NOT Instruction
Purpose: It carries out the negation of the destiny operator bit by bit.
Syntax:
NOT destiny
OR Instruction
Syntax:
OR destiny, source
The OR instruction carries out, bit by bit, the logic inclusive disjunction of the two
operators:
TEST Instruction
Syntax:
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:
Its function is to perform the logic exclusive disjunction of the two operators bit by bit.
ADC Instruction
Syntax:
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 carried.
ADD Instruction
Syntax:
It adds the two operators and stores the result on the destiny operator.
DIV Instruction
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
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
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
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:
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:
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
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
Syntax:
JA Label
After a comparison this command jumps if it is 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.
Syntax:
JAE label
JB (JNAE) Instruction
Syntax:
JB label
Syntax:
JBE label
JE (JZ) Instruction
Syntax:
JE label
Syntax:
JNE label
JG (JNLE) Instruction
Syntax:
JG label
Syntax:
JGE label
JL (JNGE) Instruction
Syntax:
JL label
Syntax:
JLE label
JC Instruction
Purpose: Conditional jump, and the flags are taken into account.
Syntax:
JC label
It jumps if there is cartage.
JNC Instruction
Purpose: Conditional jump, and the state of the flags is taken into account.
Syntax:
JNC label
JNO Instruction
Purpose: Conditional jump, and the state of the flags is taken into account.
Syntax:
JNO label
Purpose: Conditional jump, and the state of the flags is taken into account.
Syntax:
JNP label
JNS Instruction
Purpose: Conditional jump, and the state of the flags is taken into account.
Syntax:
JNP label
JO Instruction
Purpose: Conditional jump, and the state of the flags is taken into account.
Syntax:
JO label
JP (JPE) Instruction
Purpose: Conditional jump, the state of the flags is taken into account.
Syntax:
JP label
JS Instruction
Purpose: Conditional jump, and the state of the flags is taken into account.
Syntax:
JS label
LOOP Instruction
Syntax:
LOOP label
The loop instruction decreases CX on 1, and transfers the flow of the program to the label
given as operator if CX is different than 1.
LOOPE Instruction
Syntax:
LOOPE label
LOOPNE Instruction
Syntax:
LOOPNE label
This instruction decreases one from CX and transfers the flow of the program only if ZF
is different to 0.
DEC
INC
DEC Instruction
Purpose: To decrease the operator.
Syntax:
DEC destiny
This operation subtracts 1 from the destiny operator and stores the new value in the same
operator.
INC Instruction
Syntax:
INC destiny
The instruction adds 1 to the destiny operator and keeps the result in the same destiny
operator.
CMP
CMPS (CMPSB) (CMPSW)
CMP Instruction
Syntax:
This instruction subtracts the source operator from the destiny operator but without this
one storing the result of the operation, and it only affects the state of the flags.
Syntax:
DI is used as an index for the extra segment of the source chain, and SI as an index of the
destiny chain.
It only affects the content of the flags and DI as well as SI are incremented.
CLC
CLD
CLI
CMC
STC
STD
STI
CLC Instruction
Syntax:
CLC
This instruction turns off the bit corresponding to the cartage flag, or in other words it
puts it on zero.
CLD Instruction
Syntax:
CLD
This instruction turns off the corresponding bit to the address flag.
CLI Instruction
Syntax:
CLI
This instruction turns off the interruptions flag, disabling this way those maskarable
interruptions.
A maskarable interruptions is that one whose functions are deactivated when IF=0.
CMC Instruction
Syntax:
CMC
This instruction complements the state of the CF flag, if CF = 0 the instructions equals it
to 1, and if the instruction is 1 it equals it to 0.
STC Instruction
Syntax:
STC
STD Instruction
Syntax:
STD
STI Instruction
Syntax:
STI
The instruction activates the IF flag, and this enables the maskarable external
interruptions ( the ones which only function when IF = 1).