在 MASM 程序集中,如果用户写“-22”,我想检查第一个字符是否有“-”符号,然后删除它。如果用户写“+12”,我想检查第一个字符是否有“+”号,然后删除它。
下面的代码不起作用。有人可以让我知道代码有什么问题。
insertNums:
lodsb
cmp ch, 43 ;I am not sure if this is the proper way of checking for a "+"
je convertPos
cmp ch, 45 ;Same with this. Does this check for ASCII 45 which is "-"?
je convertNeg
continue:
cmp eax, 0
je endInsert
sub eax, 48
mov ebx, eax
mov eax, value
mov edx, 10 ;multiplies by 10
imul edx
jc tooLargeNumber ; check for carry after multiply
add eax, ebx ;add the digit to the converted value
jc tooLargeNumber ; check for carry after adding
mov value, eax ; store temporary value from eax
mov eax, 0 ; reset eax
loop insertNums
jmp endInsert
convertPos:
; this is for positive numbers
; the goal is to just drop the'+' sign and feed it back to the loop
convertNeg:
; this one is supposed to drop the '-' sign
; and once I know it is a negative number, I would have a separate procedure for ;converting the number to a negative