【问题标题】:Assembly at&t syntax, return an ascii integer汇编 at&t 语法,返回一个 ascii 整数
【发布时间】: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。我做错了什么?

【问题讨论】:

    标签: assembly x86 ascii intel


    【解决方案1】:

    您需要通过将结果乘以 10 来累积结果(可能在寄存器中),然后添加新数字。基本以 10 为基数的表示。您所做的最终将结果数字存储在基数 256 中。

    【讨论】:

    • @Bewn - 不,但是将一个数字乘以 10 然后再添加一个数字应该不难...
    • 好吧,我今晚试试。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多