使用一串 ASCII 数字从 100 中减去 1 的结果不正确

问题描述 投票:0回答:0
section .bss
num: resb 3
  
section .text
global _start
_start:
 ; Read input
 mov eax, 3
 mov ebx, 0
 mov ecx, num
 mov edx, 3
 int 80h
   
  sub byte [num+2], 1
  cmp byte [num+2], 255
jne skip_borrow
   
   sub byte [num+1], 1
   cmp byte [num+1], 255
jne skip_borrow

   sub byte [num], 1

skip_borrow:
   cmp byte [num], 0
jne skip_carry
   mov byte [num+1], 9
   mov byte [num+2], 9  
skip_carry:      

 mov eax, 4
 mov ebx, 1
 mov ecx, num
 mov edx, 3
 int 80h

 mov eax, 1
 mov ebx, 0
 int 80h

代码正在读取三位输入数字和一位数字输入数字。从低于 100 和高于 100 的数字中减去一位数。但是,从 100、200、300 中减去会给出错误的输出。例如,100 减 1 得到 10/ 不是 99 或 099,200 减 1 得到 20/ 不是 199。我该如何解决这个问题。

assembly x86 nasm bigint bcd
© www.soinside.com 2019 - 2024. All rights reserved.