【发布时间】:2014-03-24 10:39:48
【问题描述】:
我知道你可以加 48 将十进制转换为 ascii 或减去 48 将 ascii 转换为十进制,但为什么下面的代码也执行相同的转换?
; moving the first number to eax register and second number to ebx
; and subtracting ascii '0' to convert it into a decimal number
mov eax, [number1]
sub eax, '0'
和
; add '0' to to convert the sum from decimal to ASCII
add eax, '0'
【问题讨论】:
-
你应该谈论数字,而不是数字。
-
只要
eax中的数字是0和9之间的一个十进制数字,它就可以工作。因为 ASCII '0' 减去 '0' 是数字0,ASCII '1' 减去 '0' 是数字1等等。如果您有更大的数字,您可以逐位转换。 -
好的,所以它基本上在ascii中执行加法和减法。有道理,谢谢。
标签: assembly type-conversion decimal ascii nasm