Assembly x86 NASM程序集-将输入与整数值进行比较

Assembly x86 NASM程序集-将输入与整数值进行比较,assembly,if-statement,x86,nasm,Assembly,If Statement,X86,Nasm,我试图将输入数据与整数值进行比较 这里是我使用的基本代码 section .bss input resb 2 section .text global _start _start: mov eax, 3 mov ebx, 1 mov ecx, input mov edx, 5 int 0x80 mov eax, [input] cmp eax, 20 // This is what I cannot get to work, it

我试图将输入数据与整数值进行比较

这里是我使用的基本代码

section .bss
    input resb 2

section .text
global _start
_start:
    mov eax, 3
    mov ebx, 1
    mov ecx, input
    mov edx, 5
    int 0x80
    mov eax, [input]
    cmp eax, 20 // This is what I cannot get to work, it never compares it to 20 even if i enter 20 as input
    je next
我真正想知道的是如何在汇编中使用If语句将输入与整数进行比较


我非常感谢您的帮助。

您正在将
eax
(输入
的第一个字节)与整数进行比较。这是DC4控制字符,几乎可以肯定不是您的输入

如果要与数字20进行比较,则需要先将输入转换为数字(并接受多个字符的输入)。

尝试使用此代码

section .bss
    input resb 2

section .text
global _start
_start:
    mov eax, 3
    mov ebx, 1
    mov ecx, input
    mov edx, 5
    int 0x80
    mov eax, dword[input];dword is require for double word size
    cmp eax, 20 
    je next

好的,有没有快速的方法将输入转换成数字?或者有没有办法将20转换成可比值?我试过的其他代码是:mov eax,[num1]sub eax,'0'cmp eax,20我只是不知道如何将输入转换为整数值
atoi
libc函数可能很有趣。我修复了你的帖子。请考虑将来使用适当的代码块。