我发誓我今天已经阅读了 20 多页,从 NASM 的手册到大学指南到维基百科,再到介于两者之间的所有内容,但我无法理解这一点,我编写了一个程序来比较用户输入与0 或 1,然后根据它采取行动(一旦我在 Assembly 中掌握了它们的窍门,我可能应该使用一个数组),但现在就可以了。
问题是,我的检查从来没有用过,它们总是直接进入错误标签,我查看了x86 NASM 程序集 - 输入问题,看起来很相似但并不完全相同,我真的不需要存储用户的输入,只需检查它是什么并对其做出反应。
这是我的代码的简化版本,它应该在输入两个连续的 0 后退出,显然我无法测试它,因为我无法弄清楚用户输入了什么。
如果这是一个愚蠢的问题,我很抱歉,但本周大会得到了最好的我。
; constants
section .data
  lblZero:      db    'Zero';
  lblOne:       db    'One ';
  lblNumLength: db    0x4;
  tmp:          db    0;
; code
section .text
  global _start
; linker needs this, 'main'
_start:
loop:
  ; user was already prompted for a single digit
  ; store user's input ; read
  mov rax, 0 ;
  mov rbx, 19 ;
  mov rcx, tmp ;
  mov rdx, 10 ;
  syscall
  ; series of IFs
  cmp   rcx, 0    ; is input 0? 00 exits the program
  je    isZero
  cmp   rcx, 1    ; is input 1?
  je    isOne  
  jmp   exit  
; user typed 0
isZero:
  inc   rcx               ; flag for 0
  cmp   rcx, 2            ; checking if this is the 2nd zero
  je    exit              ; if so, we are outta here
  mov   rsi, lblZero ;
  mov   rcx, -1 ;
  jmp  print ;
; user typed 1
isOne:
  mov   rsi, lblOne ;
  mov   rcx, -1 ;
  jmp  print ;
; prints the string into the screen ; sys_write
print:
  mov   rax, 1 ;           
  mov   rdi, 1 ;         
  mov   rdx, lblNumLength ;       
  syscall
  jmp   loop
; displays an error message
err:
  ; sys_write, not relevant to the Q     
  syscall
  jmp loop
; shutsdown program ; sys_write ; sys_exit
exit:
  ; not relevant to the Q, code always ends here
我在这里读到http://www.cin.ufpe.br/~if817/arquivos/asmtut/index.html#stack输入不是真正的int,而是一个字符,所以我尝试创建只存储'1 ' 或 '0' 但似乎没有任何作用。
我是Assembly的超级新手,所以如果我在这里做得很愚蠢,如果你指出我将不胜感激。