C语言修改const变量

4 篇文章 0 订阅

const

code

c code

int main()
{
    const int ret = 0;
    int *p = (int*)&ret;

    *p = 4;

    return ret + *p;
}

asm code

$ lldb const
(lldb) target create "const"
Current executable set to 'const' (x86_64).
(lldb) disassemble -name main
const`main:
const[0x100000f80] <+0>:  pushq  %rbp
const[0x100000f81] <+1>:  movq   %rsp, %rbp
const[0x100000f84] <+4>:  leaq   -0x8(%rbp), %rax
const[0x100000f88] <+8>:  movl   $0x0, -0x4(%rbp)
const[0x100000f8f] <+15>: movl   $0x0, -0x8(%rbp)
const[0x100000f96] <+22>: movq   %rax, -0x10(%rbp)
const[0x100000f9a] <+26>: movq   -0x10(%rbp), %rax
const[0x100000f9e] <+30>: movl   $0x4, (%rax)
const[0x100000fa4] <+36>: movq   -0x10(%rbp), %rax
const[0x100000fa8] <+40>: movl   (%rax), %ecx
const[0x100000faa] <+42>: addl   $0x0, %ecx
const[0x100000fad] <+45>: movl   %ecx, %eax
const[0x100000faf] <+47>: popq   %rbp
const[0x100000fb0] <+48>: retq  

lldb 用法

http://lldb.llvm.org/lldb-gdb.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值