The AAM instruction
Adjusting the AX register after multiplication.
The AAM instruction format
| Instruction | Description |
|---|---|
| AAM | Adjusting the AX register after multiplication |
| AAM imm8 | Adjusting the AX register after multiplication by the numeric radix imm8 |
Adjusts the result of multiplying two unpacked BCD values to create a pair of unpacked BCD values (base 10). The ax register is the implied source and destination operand for this instruction. The aam instruction is useful only when it follows an mul instruction that multiplies two unpacked BCD values and stores a word result in the ax register. The aam instruction then adjusts the contents of the ax register so that it contains the correct 2-digit unpacked BCD result (base 10).
The generalized version of this instruction allows the contents of the ax register to be adjusted to create two unpacked digits of any number base. Here the imm8 byte is set to the selected number base (for example, 08h for octal, 0Ah for decimal, or 0Ch for base 12 numbers). The aam mnemonic is interpreted by all assemblers as meaning adaptation to ASCII values (base 10). To adjust to values in another number base, the instruction must be hand-coded in machine code (D4 imm8).
First example: 13 * 2
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov al, 13 ; Copy the value 13 into the al register mov bl, 2 ; Copy the value 2 into the bl register mul bl ; Multiply the value in the al register by the value in the bl register aam ; Adjust the contents of the al register mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Second example: 3 * 4 * 2 with screen output
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov al, 3 ; Copy the value 3 into the al register mov bl, 4 ; Copy the value 4 into the bl register mul bl ; Multiply the ax register by the bl register mov bl, 2 ; Copy the value 2 into the bl register mul bl ; Multiply the ax register by the bl register aam ; Adjust the contents of the al register mov bx, ax ; Save the value of the ax register in the bx register or bx, 3030h ; Convert the value in the bx register into an ASCII number mov ah, 02h ; Copy the console output function number into ah mov dl, bh ; Copy the ASCII number from the bh register into the dl register int 21h ; Call the interrupt mov dl, bl ; Copy the ASCII number from the bl register into the dl register int 21h ; Call the interrupt mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Third example: 3 * 4 with output in the octal system
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov al, 3 ; Copy the value 3 into the al register mov bl, 4 ; Copy the value 4 into the bl register mul bl ; Multiply the ax register by the bl register db 0D4h, 8 ; Adjust the contents of the al register for the octal system mov bx, ax ; Save the value of the ax register in the bx register or bx, 3030h ; Convert the value in the bx register into an ASCII number mov ah, 02h ; Copy the console output function number into ah mov dl, bh ; Copy the ASCII number from the bh register into the dl register int 21h ; Call the interrupt mov dl, bl ; Copy the ASCII number from the bl register into the dl register int 21h ; Call the interrupt mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".