汇编
好好学习啊天天向上
这个作者很懒,什么都没留下…
展开
-
cmp的问题
1)下面的代码运行正确 leaq (%rbx,%rbp), %rdi addq %r12, %rdi cmpl $2, %r10d leaq (%rcx,%rdi,8), %rax jle .L62)这样的代码也运行正确 leaq (%rbx,%rbp), %rdi addq %r12, %rdi leaq (%rcx,%rdi,8), %rax cmpl $2, %r10d jle .L6...原创 2022-04-07 15:34:45 · 126 阅读 · 0 评论 -
汇编,CFA,CFI
1)来源.cfi_def_cfa_offset directives in assembly generated by GCC不知道intel有没有。main()is called from somewhere else (in thelibcC runtime support code), and, at the time thecallinstruction is executed,%rspwill point to the top of the stack (which is...原创 2022-04-06 10:19:47 · 1597 阅读 · 0 评论 -
X86 64 汇编要注意的地方
1)不可能对MOV的两个参数使用相对基址寻址:MOVQ -8(%rbx), -8(%rbx)。要查看是否支持寻址模式的组合,您需要阅读手册的相关说明。2)IMUL 指令稍有不同:它把%rax的值乘以操作数,把结果的低64位存在%rax,高64位放在%rdx (两个64位值相乘的结果是128位)。IDIV则相反,把128bit值(低64位在 %rax ,高64位在%rdx)除以指令中的操作数(为了正确处理负数,用CDQO 指令把%rax符号扩展到%rdx),商存储在%rax,余数在%rdx。3原创 2022-04-03 16:46:27 · 643 阅读 · 0 评论 -
X86 Linux 汇编 GDB 调试
mov (%rax) %rax寄存器中%rax所保存的内存地址对应位置的值加载进%raxmov -8(%rbp) rax将%rbp内存所保存的值减8作为内存地址,喷对应的内存地址中的值进%raxmovq (%rcx,%rax,8) %rax将R[%rcx]+R[%rax]*8对应的地址的值加载进%rax有效地址=offset(%base,%index,scale)=偏移量(基数,索引,倍数)offset,scale必须是常量%base,%index必须是寄存器scale必须是1,2.原创 2022-03-27 17:03:01 · 566 阅读 · 1 评论 -
CFI,CFA
CFI(calling frame info)的作用是出现异常时stack的回滚(unwind)而回滚的过程是一级级CFA往上回退,直到异常被catch。Assembler Directives都属于汇编的指导语。可以看下MIT的教程:https://web.mit.edu/rhel-doc/3/rhel-as-en-3/index.htmlThe callframeis identified by an address on the stack. We refer to t..原创 2022-03-27 14:46:01 · 466 阅读 · 0 评论 -
汇编,打印寄存器的值
1).LC0: .string "%d\n" .section .text.startup,"ax",@progbits .p2align 4,,15 .globl main .type main, @function2)把$5变成相应的寄存器就行。 movl $5, %esi leaq .LC0(%rip), %rdi call printf@PLT3) .file "b6.array.c" .text .section .rodata.str1.1,"aMS原创 2022-03-24 23:28:21 · 2072 阅读 · 4 评论 -
汇编,数组
1)#include <stdio.h>void main(){ int ss=0; int arr[100]; for(int i=0;i<100;i++) { arr[i]=i; } for(int i=0;i<100;i++) { ss=ss+arr[i]; } printf("%d\n",ss);}2) -O0 -S差不多能够看懂,不知道allo原创 2022-03-24 20:48:43 · 510 阅读 · 0 评论 -
汇编 循环
1)代码,1到100累加求和#include <stdio.h>void main(){ int ss=0; for(int i=1;i<100;i++) { ss=ss+i; } printf("%d\n",ss);}2)运行命令:rm b5.loop.s b5.exe -f ; gcc -O0 -S b5.loop.c ; gcc -o b5.exe b5.loop.s ; ./b5.exe3)原创 2022-03-24 02:13:02 · 376 阅读 · 0 评论 -
汇编 hello world
1)C代码,经典中的经典#include <stdio.h>void main(){ printf("Hello world 123\n");}2)生成汇编gcc -S -O0 b4.hello.c3)原始的 .file "b4.hello.c" .text .section .rodata.LC0: .string "Hello world 123" .text .globl main .type main, @functionmain原创 2022-03-24 01:54:01 · 1152 阅读 · 0 评论 -
X86汇编代码分析-函数调用
1)int add(int i, int j){ return i + j;}int main(){ int a = 1; int b = 7; a = add(a, b); printf("%d\n",a);}汇编代码: .file "ex3.c" .text .globl add .type add, @functionadd:.LFB0: .cfi_startproc pushq %rbp # rbp入栈, 把rbp里的原创 2022-03-24 01:11:21 · 1729 阅读 · 0 评论 -
gcc编译的四个阶段:预处理,编译,汇编,链接,中间代码生成
#gcc-Emap.c-omap.i//-E查看且预处理后停止编译,-o生成目标文件,-i表示已预处理#gcc-Smap.i-omap.s//-S编译到汇编而不进行汇编和链接#gcc-cmap.s-omap.o//-c编译到目标代码#gccmap.o-omap//-o文件输出到文件#gcc-staticmap.c-omap//-static...原创 2019-09-21 09:38:12 · 755 阅读 · 0 评论