【发布时间】:2012-03-02 00:26:24
【问题描述】:
下面的代码以 ASCII 格式接收一个两位数(比如说 12),并应将此数字作为数字 12 返回。(不是 ASCII)
mov $IBUFF, %eax # IBUFF stores the ASCII number 12
movl $NUMBER, %ecx # NUMBER will i put the number 12 (NO ASCII)
movb (%eax), %bl # Moves the first byte (1) to %bl
subb $48, %bl # Decrease %bl so it is not longer a ASCII sign.
movb %bl, (%ecx) # Moves this byte into the first place in NUMBER
inc %eax # Increase IBUFF so it points to the next integer
inc %ecx # Increase NUMBER so it points to the next empty space
movb (%eax), %bl # Same as above
subb $48, %bl # Same as above
movb %bl, (%ecx) # Same as above
mov NUMBER, %eax # Move the number 12 from NUMBER to %eax (return register)
当我运行这段代码时,返回值为 513,而不是 12。我做错了什么?
【问题讨论】: