You are on page 1of 16

Lecture 2-3.

Main unprivileged
commands
Data transfer
Command: MOV receiver, source
Purpose: Data transfer

Command: CMOVcc receiver, source


Purpose: Conditional data transfer

Command: XCHG operand1, operand2


Purpose: Exchange of operands between themselves

Command: BSMAP register32


Purpose: Exchange of bytes in the register

Command: PUSH source


Purpose: Data placement in a stack
Lecture 2-3. Main unprivileged
commands
Table 5. Command species CMOVcc
Lecture 2-3. Main unprivileged
commands
Command: POP receiver
Purpose: Read out data from a stack

Command: PUSHA
PUSHAD
Purpose: Place all registers of general purpose in a
stack

Command: POPA
POPAD
Purpose: Load all registers of general purpose from a
stack

Command: IN receiver, source


Purpose: Read out data from the port
Lecture 2-3. Main unprivileged
commands

Command: OUT receiver, source


Purpose: Write down data to the port

Command: CWD
Purpose: Word converting in the double word

Command: CDQ
Purpose: Double word converting in the quadruple word

Command: CBW
Purpose: Byte converting in the word

Command: CWDE
Purpose: Word converting in the double word
Lecture 2-3. Main unprivileged
commands

Command: MOWSX receiver, source


Purpose: Transfer with sign extension

Command: MOWZX receiver, source


Purpose: Transfer with extension with zeroes

Command: XLAT address


XLATB
Purpose: Translation according to the table

Command: LEA receiver, source


Purpose: Calculation of the effective address
Lecture 2-3. Main unprivileged
commands
Binary Arithmetics
Command: ADD receiver, source
Purpose: Addition

Command: ADC receiver, source


Purpose: Addition with carryover

Command: XADD receiver, source


Purpose: Exchange between themselves and add

Command: SUB receiver, source


Purpose: Subtraction

Command: SBB receiver, source


Purpose: Subtraction with a borrow
Lecture 2-3. Main unprivileged
commands

Command: IMUL source


IMUL receiver, source
IMUL receiver, source1, source2
Purpose: Multiplication of numbers with a sign

Command: MUL source


Purpose: Multiplication of numbers without a sign

Command: IDIV source


Purpose: Integer-valued division with a sign

Command: DIV source


Purpose: Integer-valued division without a sign

Command: INC receiver


Purpose: Increment
Lecture 2-3. Main unprivileged
commands

Command: DEC receiver


Purpose: Decrement

Command: NEG receiver


Purpose: Sign change

Command: CMP receiver, source


Purpose: Comparison

Command: CMPXCHG receiver, source


Purpose: Compare and exchange between themselves

Command: CMPXCHG8B receiver


Purpose: Compare and exchange eight bytes
Lecture 2-3. Main unprivileged
commands
Decimal arithmetics
Command: DAA
Purpose: Correction after addition
DAA executes the following actions:
If low four bits of AL are more than 9 or flag AF = 1, AL increases on 6, CF
is established, if at this addition there was a carryover, and AF is
established in 1.
Otherwise AF = 0.
If now high four bits of AL is more than 9 or flag CF = 1, AL increases on
60h and CF is established in 1.
Otherwise CF = 0.
Command: DAS
Purpose: Correction after subtraction
DAS executes the following actions:
If low four bits of AL are more than 9 or flag AF = 1, AL increases on 6, CF
is established, if at this subtraction there was a borrow, and AF is
established in 1.
Otherwise AF = 0.
If now high four bits of AL is more than 9 or flag CF = 1, AL increases on
60h and CF is established in 1.
Otherwise CF = 0.
Lecture 2-3. Main unprivileged
commands
Examples of using commands DAA and DAS
Command: DAA
If this command is executed right after ADD (ADC, INC or XADD) and in the register AL
there is a sum of two packed binary-decimal numbers, as a result in AL the packed binary-
decimal number which had to be result of addition registers. For example, if AL contains
number 19h, sequence of commands
inc al
daa
will lead to that in AL will appear 20h (instead of 1Ah as would be after INC).

Command: DAS
If this command is executed right after SUB (SBB or DEC) and in the register AL there is a
difference of two packed binary-decimal numbers, as a result in AL the packed binary-
decimal number which had to be result of subtraction registers. For example, if AL contains
number 20h, sequence of commands
dec al
das
will lead to that in AL will appear 19h (instead of 1Fh as would be after DEC).
Lecture 2-3. Main unprivileged
commands

Command: AAA
Purpose: Correction after addition
Corrects the sum of two unpacked binary-decimal numbers of AL. If correction leads to decimal
carryover, AN increases on 1. This command makes sense right after command of addition of two such
numbers. For example, if at addition 05 and 06 in AX there is a number 000Bh, command AAA will
correct it in 0101h (unpacked decimal 11). Flags of CF and OF are set in 1 if there was a carryover from
AL in AH, differently they are equal to zero. Values of flags of OF, SF, ZF and PF aren't defined.
Command: AAS
Purpose: Correction after subtraction
Corrects a difference of two unpacked binary-decimal numbers in AL right after the SUB or SBB
command. If correction leads to borrow, AH decreases on 1. Flags of CF and OF are set in 1 if there was
borrow from AL in AH, and in zero — otherwise. Values of flags of OF, SF, ZF and PF aren't defined.
Lecture 2-3. Main unprivileged
commands

Command: AAM
Purpose: Correction after multiplication
Corrects result of multiplication of the unpacked binary-decimal numbers, being in AX after execution of
the command of MUL, transforming the received result to couple of unpacked binary-decimal numbers
(in AH and AL). For example:
mov al,5
mov bl,5 ; multiple 5 by 5
mul bl ; result in АХ - 0019h
aam ; now АХ contains 0205h
Command: AAD
Purpose: Correction before division
Executes correction of the unpacked binary-decimal number being in the register AX so that the
subsequent division led to correct decimal result. For example, we will divide decimal 25 on 5:
mov ax,0205h ; 25 in unpacked format
mov bl,5
aad ; now АХ contains 19h
div bl ; АХ = 0005
Lecture 2-3. Main unprivileged
commands
Logical operations
Command: AND receiver, source
Purpose: Logical AND

Command: OR receiver, source


Purpose: Logical OR

Command: XOR receiver, source


Purpose: Logical exclusive OR

Command: NOT receiver


Purpose: Inversion

Command: TEST receiver, source


Purpose: Logical comparison
Lecture 2-3. Main unprivileged
commands

Shift operations
Command: SAR receiver, counter
Purpose: Arithmetic right shift

Command: SAL receiver, counter


Purpose: Arithmetic left shift

Command: SHR receiver, counter


Purpose: Logical right shift

Command: SHL receiver, counter


Purpose: Logical left shift
Lecture 2-3. Main unprivileged
commands

Figure 7. Shift Operations


Lecture 2-3. Main unprivileged
commands
Command: SHRD receiver, source, счетчик
Purpose: Right shift of extended precision

Command: SHLD receiver, source, счетчик


Purpose: Left shift of extended precision

Figure 8. Shifts of double precision

You might also like