我知道你可以加上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
,以此类推。如果您有更大的数字,您需要逐位转换。 - lurker