AAM
: ASCII Adjust AX
After Multiplication
Opcode and Mnemonic | Encoding | 16 bit Mode | 32 bit Mode | 64 bit Mode | Description |
---|---|---|---|---|---|
D4 0A AAM | ZO | Valid | Valid | Invalid | ASCII adjust AX after multiply. |
D4 ib AAM imm8 | I | Valid | Valid | Invalid | ASCII adjust AX after multiply to number base imm8. |
Encoding
Encoding | Operand |
---|---|
ZO | None (implicitly 10) |
I | imm8[r] |
Bit Encoding
- implicit 10
1101 0100
:0000 1010
- immediate
1101 0100
: immediate
Description
The AAM
instruction converts the result of a multiplication of two BCD digits to a valid 2-digit BCD number.
This instruction will not be useful unless it immediately follows an MUL
instruction.
Traditionally, this instruction is called "ASCII Adjust After Multiplication". This would lead one to believe that it works on ASCII digits (030h
(0
) through 039h
(9
)), however this would be incorrect. This instruction actually operates on BCD digits (00h
(0
) through 09h
(9
)).
Due to a quirk of history, this instruction encodes the base of the result in the instruction (the second byte). As such, it is possible to have this instruction work on other bases through an immediate 8 bit operand. Such methods are not guaranteed to be supported by your assembler, and in such situations, one must encode the instruction directly.
This instruction is not valid in 64 bit mode, and if encountered, the processor will raise a #UD
exception.
Operation
pub fn aam(imm8: u8) {
AH = AL / imm8;
AL = AL % imm8;
}
Flags Affected
CF
(carry flag)- Undefined.
PF
(parity flag)- Set based on the resulting value in
AL
. AF
(auxiliary flag)- Undefined.
ZF
(zero flag)- Set based on the resulting value in
AL
. SF
(sign flag)- Set based on the resulting value in
AL
. OF
(overflow flag)- Undefined.
Exceptions
Protected Mode
#DE
- If an immediate value of 0 is used.
#UD
- If the
LOCK
prefix is used.
Real-Address Mode
Same exceptions as protected mode.
Virtual-8086 Mode
Same exceptions as protected mode.
Compatibility Mode
Same exceptions as protected mode.
Long Mode
#UD
- If in 64 bit mode.