这个汇编代码用 ascii 做什么?
What does this Assembly code do, with ascii?
我试图理解以下汇编代码 (x86-64 att):
msg: .ascii "This is an examp" # please note it's examp not example
_start:
mov $msg, %rsi
mov , %rdi
mov , %rdx
mov , %rax
mov [=10=], %rbx
mov , %r9
call exm
exm:
cmp %rbx, %r9
je end
test , %rbx
jnz skip
syscall
skip:
inc %rsi
inc %rbx
call exm
end:
ret
将字符串存储在寄存器中是什么意思?寄存器不保持 0/1 吗?
如果它正在转换 ascci ti 字符,我知道 char 大小是 1 个字节,我们的字符串是 16 个字母,所以我们需要 16 个字节,而寄存器只有 8 个字节。怎么样?
因为 rdi 是 1 我们正在从屏幕上读取这是真的吗?
如果系统调用失败,它将 return 0 和 return 值存储在 rax 中,这是否意味着存在无限循环的可能性?
what does it mean to store string in a register? doesn't registers hold 0/1?
不知道你说的0/1是什么意思,但是msg
是一个基本等于字符串起始地址的标签。所以mov $msg, %rsi
将字符串"This is an examp"
的起始地址移动到%rsi
.
in case it's converting ascci ti chars I know that char size is 1 byte, our string is 16 letters so we need 16 bytes and the register is only 8 bytes. how is that?
同样,寄存器只保存字符串的起始地址。
since rdi is 1 we are reading from screen is this true?
不从屏幕读取,写入屏幕。您正在使用 write
系统调用,您在 %rdi
中输入要写入的文件描述符。 1
是 stdout
的文件描述符,因此它写入终端屏幕。
In case the sys-call fails it will return 0 and return value if stored in rax, does that mean there is a potential for endless loop?
write
returns -errno
(所以是负数)错误,不是 0。查看 man page 中可能的错误,我不从您的程序中查看任何可能的错误原因。由于您的程序依赖于 write
的 return 值为 1 以继续调用 write
,如果确实发生错误,您将调用一个不存在的系统调用(因为那里没有负数系统调用),在这种情况下什么也不会发生并且 rax
将被设置为 -ENOSYS
(从我所做的测试中似乎是 -38
)这又是' t 一个有效的系统调用号。我已经尝试编辑您的程序以故意以无效的系统调用编号而不是 1
开始,并且它不会导致无限循环,它只是不打印任何内容并退出。所以看起来你的程序不会导致无限循环。
我不确定在某些情况下从您的程序中正确调用 write 是否可以 return 0(意味着它不打印任何内容),但如果可以,那么下一个调用将是 read
和你的程序 会 冻结,直到你输入一些字符串(read
的参数与 write
非常相似,所以尽管是一个完全不同的系统调用,它看起来仍然是正确的 运行,虽然因为 msg
似乎是在 .text
中定义的,你不能写入它并且 -EFAULT
将被 returned这个也是)。同样,这只是假设在某些情况下 write
returns 0;我觉得这不太可能,甚至不可能。
我试图理解以下汇编代码 (x86-64 att):
msg: .ascii "This is an examp" # please note it's examp not example
_start:
mov $msg, %rsi
mov , %rdi
mov , %rdx
mov , %rax
mov [=10=], %rbx
mov , %r9
call exm
exm:
cmp %rbx, %r9
je end
test , %rbx
jnz skip
syscall
skip:
inc %rsi
inc %rbx
call exm
end:
ret
将字符串存储在寄存器中是什么意思?寄存器不保持 0/1 吗?
如果它正在转换 ascci ti 字符,我知道 char 大小是 1 个字节,我们的字符串是 16 个字母,所以我们需要 16 个字节,而寄存器只有 8 个字节。怎么样?
因为 rdi 是 1 我们正在从屏幕上读取这是真的吗?
如果系统调用失败,它将 return 0 和 return 值存储在 rax 中,这是否意味着存在无限循环的可能性?
what does it mean to store string in a register? doesn't registers hold 0/1?
不知道你说的0/1是什么意思,但是msg
是一个基本等于字符串起始地址的标签。所以mov $msg, %rsi
将字符串"This is an examp"
的起始地址移动到%rsi
.
in case it's converting ascci ti chars I know that char size is 1 byte, our string is 16 letters so we need 16 bytes and the register is only 8 bytes. how is that?
同样,寄存器只保存字符串的起始地址。
since rdi is 1 we are reading from screen is this true?
不从屏幕读取,写入屏幕。您正在使用 write
系统调用,您在 %rdi
中输入要写入的文件描述符。 1
是 stdout
的文件描述符,因此它写入终端屏幕。
In case the sys-call fails it will return 0 and return value if stored in rax, does that mean there is a potential for endless loop?
write
returns -errno
(所以是负数)错误,不是 0。查看 man page 中可能的错误,我不从您的程序中查看任何可能的错误原因。由于您的程序依赖于 write
的 return 值为 1 以继续调用 write
,如果确实发生错误,您将调用一个不存在的系统调用(因为那里没有负数系统调用),在这种情况下什么也不会发生并且 rax
将被设置为 -ENOSYS
(从我所做的测试中似乎是 -38
)这又是' t 一个有效的系统调用号。我已经尝试编辑您的程序以故意以无效的系统调用编号而不是 1
开始,并且它不会导致无限循环,它只是不打印任何内容并退出。所以看起来你的程序不会导致无限循环。
我不确定在某些情况下从您的程序中正确调用 write 是否可以 return 0(意味着它不打印任何内容),但如果可以,那么下一个调用将是 read
和你的程序 会 冻结,直到你输入一些字符串(read
的参数与 write
非常相似,所以尽管是一个完全不同的系统调用,它看起来仍然是正确的 运行,虽然因为 msg
似乎是在 .text
中定义的,你不能写入它并且 -EFAULT
将被 returned这个也是)。同样,这只是假设在某些情况下 write
returns 0;我觉得这不太可能,甚至不可能。