提问人:Merd Ceferzade 提问时间:7/25/2023 最后编辑:Merd Ceferzade 更新时间:7/25/2023 访问量:37
如何获取存储在字符串中的输入 - 程序集
How To Get Input That Is Stored In A String - Assembly
问:
我想编写一个程序集代码,打印“Hello, World!”,然后读取用户的输入,然后打印该输入。获取输入是正确的,但我无法打印它(或打印旧值)。 法典:
.global _start
.intel_syntax noprefix
_start:
# Write
mov rax, 1 # syscall number for sys_write
mov rdi, 1 # file descriptor 1 (stdout)
lea rsi, load_msg # pointer to the message to be written
mov rdx, 14 # message length
syscall
# Read
mov rax, 0 # syscall number for sys_read
mov rdi, 0 # file descriptor 0 (stdin)
lea rsi, read_msg # pointer to the buffer to store user input
mov rdx, 255 # maximum number of bytes to read
syscall
# Write
mov rax, 1 # syscall number for sys_write
mov rdi, 1 # file descriptor 1 (stdout)
mov rdx, rax
syscall # writing the user input to the standard output
# Exit
mov rax, 60 # syscall number for sys_exit
mov rdi, 0 # exit code 0
syscall
load_msg:
.asciz "Hello, World!\n"
read_msg:
.space 256
答: 暂无答案
评论
mov rdx, rax
应该在之前mov rax, 1
read_msg
.text
strace ./a.out
read
-EFAULT
lea rsi, [RIP + read_msg]