AAA acc firstnumberesi add previous carry to acc
一、AAA指令 acc = first_number[esi] add previous carry to acc save carry in carry 1 acc += second_number[esi] OR the carry with carry 1 sum[edi] = acc dec edi , esi Until ecx == 0 Store last carry digit in sum 进位数字必须转换成ASCII码,在把进位数字和第一个操作数相加的时候,必须使用AAA调整结 果,下面是程序清单: TITLE ASCII Addition (ASCII_add. asm) ; Perform ASCII arithmetic on digit strings having ; implied fixed decimal points. ; Last update: 06/01/2006 INCLUDE Irvine 32. inc DECIMAL_OFFSET = 5 offset from right of string. data decimal_one BYTE "100123456789765" decimal_two BYTE "900402076502015" sum BYTE (SIZEOF decimal_one + 1) DUP(0), 0 ; ; 1001234567. 89765 ; 9004020765. 02015
一、AAA指令. code main PROC ; Starting at the last digit position. mov esi, SIZEOF decimal_one - 1 mov edi, SIZEOF decimal_one mov ecx, SIZEOF decimal_one mov bh, 0 L 1: mov add aaa mov or ah, 0 al, decimal_one[esi] al, bh add aaa or or or mov al, decimal_two[esi] bh, ah bh, 30 h al, 30 h sum[edi], al dec esi dec edi loop L 1 mov sum[edi], bh ; Display the sum as a string. mov edx, OFFSET sum call Write. String call Crlf exit main ENDP END main ; set carry value to zero ; clear AH before addition ; get the first digit ; add the previous carry ; adjust the sum (AH = carry) ; save the carry in carry 1 ; convert it to ASCII ; add the second digit ; adjust the sum (AH = carry) ; OR the carry with carry 1 ; convert it to ASCII ; convert AL back to ASCII ; save it in the sum ; back up one digit ; save last carry digit
三、AAM指令调整MUL指令的结果,把乘积的二进制数值转换成未压缩十进制数,MUL指令必须使 用未压缩的十进制数。. data Asc. Val BYTE 05 h, 06 h. code mov bl, Asc. Val ; first operand mov al, [Asc. Val+1] ; second operand mul bl ; AX = 001 Eh AAM ; AX = 0300 h
四、AAD指令在除法操作之前调整AX中的未压缩十进制数被除数,以执行DIV指令。下面的例子把 未压缩的0307 h转换成二进制数,然后再除以 5. 执行DIV指令后,商07 h存放在AL中,余数 02 h存 放在AH中:. data quotient BYTE ? remainder BYTE ? . code mov ax, 0307 h ; dividend -十进制数‘ 37’ AAD ; AX = 0025 h mov bl, 5 ; divisor div bl ; AX = 0207 h mov quotient, al mov remainder, ah
- Slides: 11