【发布时间】:2022-01-17 21:54:09
【问题描述】:
global _start
section .data
firstMsg: db "hello worms, please say the passcode", 10
firstLen: equ $ - firstMsg
secondMsg: db "Correct", 10
secondLen: equ $ - secondMsg
thirdMsg: db "Incorrect.", 10
thirdLen: equ $ - thirdMsg
password: db "Hello"
section .bss
attempt RESB
section .data
_start:
;Print the first message
mov rax, 1
mov rdi, 1
mov rsi, firstMsg
mov rdx, firstLen
syscall
;Read input
mov rax, 0
mov rdi, 0
mov rsi, attempt
mov rdx, 10
syscall
;compare input to the password
cmp attempt, password
je L1
jne L2
syscall
;Display correct if correct
L1:
mov rax, 1
mov rdi, 1
mov rsi, secondMsg
mov rdx, secondLen
jmp L3
syscall
;display incorrect if incorrect
L2:
mov rax, 1
mov rdi, 1
mov rsi, thirdMsg
mov rdx, secondLen
syscall
;exit the program
L3:
mov rax, 60
mov rdi, 1
syscall
此代码返回此错误消息:
inout.asm:13: error: invalid combination of opcode and operands
inout.asm:33: error: invalid combination of opcode and operands
我在这里尝试做的是将用户输入作为字符串,然后将其与常量密码进行比较。如果它们相同,则打印“正确”,如果不是,则打印“不正确”并跳回第一个问题(尚未完成该部分)。
如果有人能帮我解决这个问题,那就太好了。
【问题讨论】:
-
cmp的两个操作数都是imm64s(在您的情况下为指针常量),这不是有效的(更不用说有意义的)比较。改为查看rep cmps。另外,在执行系统调用之前无条件跳转到L3似乎不合逻辑。此外,您在 BSS 部分中对attempt的定义不完整,它缺少长度并且标签缺少后缀:。最后,我认为将您的代码放入您的 data 部分是没有意义的......它应该放入.text。
标签: linux assembly x86-64 nasm