Flowchart
Untitled
Flowchart content
Defining Constants
Data Exchange and Translate Instructions
The XCHG Instruction
The xchg instruction exchanges 8-, 16, or 32-bit source and destination operands. The syntax is similar to that of the mov instruction.
xchg EAX,EDX
xchg [response],CL
xchg [total],DX
As in the mov instruction, both operands cannot be located in memory. Note that this restriction is applicable to most instructions. Thus,
xchg [response] , [namel ] ; illegal
is invalid. The xchg instruction is convenient because we do not need a third register to hold a temporary value in order to swap two values.
For example, we need three mov instructions
mov ECX,EAX
mov EAX,EDX
mov EDX,ECX
Another instruction , bswap, can be used to perform such conversions on 32-bit data.
The format is
bswap register
This instruction works only on the data located in a 32-bit register.
The XLAT Instruction
The xlat (translate ) instruction can be used to perform character translation. The format of this instruction is shown below: xlatb
To use this instruction , the EBX register must to be loaded with the starting address of the translation table and AL must contain an index value into the table.
The xlat instruction adds contents of AL to EBX and reads the byte at the resulting address.
This byte replaces the index value in the AL register
Shift and Rotate Instructions
Shift Instructions
The instruction set provides several shift instructions . We discuss the following two instructions here: shl (SHif t Left ) and shr (SHif t Right) .
The shl instruction can be used to left shif a destination operand. Each shift to the left by one bit position causes the leftmost bit to move to the carry flag (CF).
The shr instruction works similarly but shifts bits to the right as shown below:
The general formats of these instructions are:
shl destination,count
shl destination,CL
shr destination,count
shr destination,CL
The destination can be an 8-, 16 - or 32-bit operand stored either in a register or in memory.
Rotate Instructions
A drawback with the shift instructions is that the bits shifted out are lost. There may be situations where we want to keep these bits.
The rotate family of instructions provides this facility. These instructions can be divided into two types: rotate without involving the carry flag, or through the carry flag.
Rotate Without Carry
There are two instructions in this group: rol (Rotat e Left) ror (Rotate Right)
The format of instructions
rol destination,count
rol destination,CL
ror destination,count
ror destination,CL
MACROS
Macros provide a means by which a block of text (code, data, etc.) can be represented by a name (called the macro name)
Whe n the assembler encounters that name later in the program , the block of text associated with the macro name is substituted.
In NASM, macros can be defined with %macro and %endmacro directives . The macro text begins with the %macro directive and ends with the %endmacro directive. The macro definition syntax is
%macro macro_name para_count <macro body>
%endmacro
The para_count specifie s the number parameters used in the macro. The macro_name i s the name of the macro that, when used later in the program, causes macro expansion. To invoke or call a macro, use the macro_name and supply the necessary parameter values.
Macros with Parameters
The previous macro always multiplies EAX by 16 . B y using parameters, we can generalize this macro to operate on a byte, word, or doubleword located either in a general-purpose register or memory. The modified macro is
%macro mult_by_16 1
sal %1, 4
%endmacro
The EQU Directive
The %assign Directive
The %define Directive
The syntax of the EQU directive is: name EQU expression
This directive can be used to define numeric constants like the EQU directive. However, %as s ign allows redefinition. For example, we define
This directive is similar to the #define in C. It can be used to define numeric as well as string constants. For example
Information
- Description
- Flowchart on Untitled, created by Jossy Ivan Mejia Vargas on 31/10/2017.
- Created by
- Jossy Ivan Mejia Vargas
- Views
- 1
- Rating