我如何比较输入数字和汇编中的数字?

how can i compare an input number and a number in assembly?

我试图比较键盘输入和汇编中已定义的数字,但它不起作用。这就是我的代码:

; is number bigger than 5 or not

  section .text
  global _start

_start:
  
  mov eax, 4
  mov ebx, 1
  mov ecx, asknum
  mov edx, lennum
  int 80h

  mov eax, 3
  mov ebx, 0
  mov ecx, num
  mov edx, 5
  int 80h
  
  mov eax, [num]
  sub eax, '0'

  cmp eax, num5
  jg gt5 
  jl lt5
  int 80h
  jmp cont

cont:
  int 80h
  mov eax, 4
  mov ebx, 1
  mov ecx, ifequ
  mov edx, lene
  int 80h
  jmp end

gt5:
  int 80h

  mov eax, 4
  mov ebx, 1
  mov ecx, resifyes
  mov edx, lenyes
  int 80h
  jmp end

lt5:
  int 80h

  mov eax, 4
  mov ebx, 1
  mov ecx, resifno
  mov edx, lenno
  int 80h
  jmp end

end:
  mov eax, 1
  int 80h

  section .data
asknum: db "Please enter a number and i will tell you if your number bigger than 5 or not: ", 0xa, 0xd
lennum: equ $-asknum

ifequ: db "Your number is equal to five.", 0xa, 0xd
lene: equ $-ifequ

resifno: db "No, your number not bigger than 5.", 0xa, 0xd
lenno: equ $-resifno

resifyes: db "Yes, your number bigger than 5", 0xa, 0xd
lenyes: equ $-resifyes

num5: db 5

  segment .bss
num resb 5

但我收到相同的线路'no, your number not bigger than 5.' 我用 nasm 和 ld 编译,所以也许我错过了一些标志,但我找不到。

我尝试了关于数据类型的所有方法,但我仍然无法解决它。顺便说一句,如果你需要,我会尝试在 linux 上执行。

当从 num 加载并与 [=14 进行比较时,您应该使用 8 位寄存器 (al) 而您使用的是 32 位寄存器 (eax) =].更正语法以便与 num5 的值而不是地址进行比较,您将得到:

mov al,[num]
sub al,'0'

cmp al,[num5]