本文介绍了需要帮助使用 Visual Studio .asm 文件以汇编语言显示带小数位的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
需要帮助使用 Visual Studio .asm 文件以汇编语言显示带小数位的数字.
例如,10 除以 4 将是 2.5 但它只显示 2
Need help to display number with decimal places in assembly language using visual studio .asm file.
For instance, 10 divide 4 will be 2.5 but it only displays 2
mov eax, 10
mov ebx, 4
xor edx, edx
div ebx
call WriteDec
推荐答案
DIV
提供整数商和余数作为结果.根据余数,您可以通过乘以 10 并除以除数来构造小数点后的整数:
DIV
offers as result both the integer quotient and the remainder. From the remainder you can construct an integer number after the decimal point by multiplying it by 10 and dividing it by the divisor:
INCLUDE Irvine32.inc
.CODE
main PROC
mov eax, 10 ; Dividend
mov ebx, 4 ; Divisor
xor edx, edx ; High 32 bit of dividend
div ebx ; Result: EAX, remainder in EDX
call WriteDec ; http://programming.msjc.edu/asm/help/index.html?page=source%2Firvinelib%2Fwritedec.htm
mov al, '.' ; Decimal point
call WriteChar ; http://programming.msjc.edu/asm/help/index.html?page=source%2Firvinelib%2Fwritechar.htm
imul eax, edx, 10 ; EAX = EDX * 10 i.e. New dividend = Old remainder * 10
xor edx, edx ; Clear the high part of dividend
div ebx ; EAX rem. EDX = EDX:EAX / EBX
call WriteDec ; http://programming.msjc.edu/asm/help/index.html?page=source%2Firvinelib%2Fwritedec.htm
exit
main ENDP
END main
根据所需的小数位数,您可以重复此过程.
Depending on the desired number of decimal places, you can repeat this procedure.
这篇关于需要帮助使用 Visual Studio .asm 文件以汇编语言显示带小数位的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!