我有一个我已经拆解的C++程序,看起来程序集正在使用指令指针获取字符串文字.例如:
leaq 0x15468(%rip), %rsi ## literal pool for: "special"
Run Code Online (Sandbox Code Playgroud)
和
leaq 0x15457(%rip), %rsi ## literal pool for: "ordinary"
Run Code Online (Sandbox Code Playgroud)
为什么编译器使用指令指针获取字符串文字?这似乎会导致任何人类程序员的头痛,尽管对编译器来说可能并不那么难.
不过,我的问题是为什么?有没有基于机器或历史的原因或编译器编写者是否决定%rip任意使用?
我有一个内存位置,其中包含一个我想要与另一个角色进行比较的角色(并且它不在堆栈的顶部,所以我不能只是pop它).如何引用内存位置的内容以便进行比较?
基本上我如何在语法上做到这一点.
I have tried to compile c code to assembly code using gcc -S -fasm foo.c.
The c code declare global variable and variable in the main function as shown below:
int y=6;
int main()
{
int x=4;
x=x+y;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
now I looked in the assembly code that has been generated from this C code and I saw, that the global variable y is stored using the value of the rip instruction pointer.
I thought that only const …
源代码:
int main()
{
int i;
for(i=0, i < 10; i++)
{
printf("Hello World!\n");
}
}
Run Code Online (Sandbox Code Playgroud)
转储函数的 Intel 语法 x86 汇编代码main:
1. 0x000055555555463a <+0>: push rbp
2. 0x000055555555463b <+1>: mov rbp,rsp
3. 0x000055555555463e <+4>: sub rsp,0x10
4. 0x0000555555554642 <+8>: mov DWORD PTR [rbp-0x4],0x0
5. 0x0000555555554649 <+15>: jmp 0x55555555465b <main+33>
6. 0x000055555555464b <+17>: lea rdi,[rip+0xa2] # 0x5555555546f4
7. 0x0000555555554652 <+24>: call 0x555555554510 <puts@plt>
8. 0x0000555555554657 <+29>: add DWORD PTR [rbp-0x4],0x1
9. 0x000055555555465b <+33>: cmp DWORD PTR [rbp-0x4],0x9
10. 0x000055555555465f …Run Code Online (Sandbox Code Playgroud) 我有一个适用于Mac OS X的程序集hello world程序,如下所示:
global _main
section .text
_main:
mov rax, 0x2000004
mov rdi, 1
lea rsi, [rel msg]
mov rdx, msg.len
syscall
mov rax, 0x2000001
mov rdi, 0
syscall
section .data
msg: db "Hello, World!", 10
.len: equ $ - msg
Run Code Online (Sandbox Code Playgroud)
我想知道这条线lea rsi, [rel msg]。为什么NASM强迫我这样做?据我了解,它msg只是指向可执行文件中某些数据的指针,这样做mov rsi, msg会将地址放入rsi。但是,如果我将替换为lea rsi, [rel msg],则NASM会引发此错误(注意:我使用的是命令nasm -f macho64 hello.asm):
hello.asm:9: fatal: No section for index 2 offset 0 found
Run Code Online (Sandbox Code Playgroud)
为什么会这样?有什么特别之处lea是mov …
我在反汇编程序(浮点逻辑c ++)中找到了以下汇编代码。
842: movss 0x21a(%rip),%xmm0
Run Code Online (Sandbox Code Playgroud)
我知道,当进程rip将一直为842且此0x21a(%rip)将为const。使用该寄存器似乎有些奇怪。
我想知道使用rip相对地址代替其他寻址有什么好处。