gpt4 book ai didi

c - 排除此 asm x86 代码的意义

转载 作者:太空宇宙 更新时间:2023-11-04 02:30:14 25 4
gpt4 key购买 nike

首先,这是汇编代码:

/           0x000006a0      55             push rbp                             
| 0x000006a1 4889e5 mov rbp, rsp
| 0x000006a4 4883ec10 sub rsp, 0x10
| 0x000006a8 488d05b50000. lea rax, str.AAAA ; 0x764

| 0x000006af 488945f8 mov qword [local_8h], rax
| 0x000006b3 488b45f8 mov rax, qword [local_8h]

| 0x000006b7 4889c6 mov rsi, rax
| 0x000006ba 488d3da80000. lea rdi, 0x00000769 ; "%s"
| 0x000006c1 b800000000 mov eax, 0
| 0x000006c6 e895feffff call sym.imp.printf ;[2] ; i
| 0x000006cb b800000000 mov eax, 0
| 0x000006d0 c9 leave
\ 0x000006d1 c3 ret

到这个c程序:

#include <stdio.h>
#include <string.h>

int main(){

char* a = "AAAA";

printf("%s", a);
return 0;
}

特别是我对这段代码有疑问:

|           0x000006af      488945f8       mov qword [local_8h], rax            
| 0x000006b3 488b45f8 mov rax, qword [local_8h]

这两条指令的意义是什么?我只以一种方式看到相同的指令,而不是相反。但这是为什么呢?

这里是可执行文件的一些进一步信息:

blksz    0x0
block 0x100
fd 6
file demo
format elf64
iorw false
mode -r--
size 0x20e0
humansz 8.2K
type DYN (Shared object file)
arch x86
binsz 6559
bintype elf
bits 64
canary false
class ELF64
crypto false
endian little
havecode true
intrp /lib64/ld-linux-x86-64.so.2
lang c
linenum true
lsyms true
machine AMD x86-64 architecture
maxopsz 16
minopsz 1
nx true
os linux
pcalign 0
pic true
relocs true
relro partial relro
rpath NONE
static false
stripped false
subsys linux
va true

最佳答案

行彼此分开:

第一行属于char* a = "AAAA";行,将变量的值保存到RAM中。

第二行从 RAM 中访问 printf("%s", a); 行的变量作为参数。

从技术上讲,这两行都是可选的,您可以这样写:

printf("%s", "AAAA");

编辑: 要跳过这些不必要的代码,您可以启用自动优化(对于 GCC:-O2)

关于c - 排除此 asm x86 代码的意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44287482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com