Opcode | Encoding | 16-bit | 32-bit | 64-bit | Description |
---|---|---|---|---|---|
D4 0A AAM | zo | Valid | Valid | Invalid | ASCII adjust AX after multiplication. |
D4 ib AAM imm8 | i | Valid | Valid | Invalid | ASCII adjust AX after multiplication to number base imm8. |
Encoding
Encoding | Operand |
---|---|
zo | None (implicitly 10) |
i | imm8 |
Description
The AAM
instruction converts the result of a multiplication of two BCD digits to a valid 2-digit BCD number.
Traditionally, this instruction is 'ASCII Adjust After Multiplication'. This would lead one to believe that it works on ASCII digits (30h
("0"
) through 39h
('9'
)), however, this is incorrect. This instruction actually operates on binary coded decimal (BCD) digits (00h
through 09h
).
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 Long Mode.
Operation
public void AAM(U8 imm8)
{
AH = AL / imm8;
AL = AL % imm8;
}
Flags Affected
CF
(carry flag)- Undefined.
PF
(parity flag)- Set according to the result.
AF
(auxiliary flag)- Undefined.
ZF
(zero flag)- Set according to the result.
SF
(sign flag)- Set according to the result.
OF
(overflow flag)- Undefined.
Exceptions
Exception | Mode | Cause of Exception | |||
---|---|---|---|---|---|
Real Mode | Virtual 8086 | Protected and Compatibility | Long Mode | ||
#DE | X | X | X | If an immediate value of 0 is used. | |
#UD | X | X | X | If the LOCK prefix is used. | |
X | If in Long Mode. |