- 论坛徽章:
- 0
|
- .data
- foo:
- .int -40
- out:
- .asciz "%d\n"
- .text
- .globl main
- main:
- xor %rax,%rax
- xor %rcx,%rcx
- movq $-20, %rax
- addq $-40, %rax
- #movq $-40, %rcx
- movq %rax, %rsi
- movq $out, %rdi
- call printf
- movq $1, %rax
- movq $0, %rbx
- int $0x80
复制代码 上面的代码一运行就会导致段错误,printf不能打印出信息
将rax的操作改成对rcx的操作以后就没问题了,下面的代码是可以正常工作 的,这是为什么呢?运行环境是x64 opensuse13.1
Thread model: posix
gcc version 4.8.1 20130909 [gcc-4_8-branch revision 202388] (SUSE Linux)
- .data
- foo:
- .int -40
- out:
- .asciz "%d\n"
- .text
- .globl main
- main:
- xor %rax,%rax
- xor %rcx,%rcx
- movq $-20, %rcx
- addq $-40, %rcx
- #movq $-40, %rcx
- movq %rcx, %rsi
- movq $out, %rdi
- call printf
- movq $1, %rax
- movq $0, %rbx
- int $0x80
复制代码 |
|