问题描述
考虑下面的短节目。
INT的main(){
ASM(MOVQ 0x5F5E100,RCX%;
startofloop:;
子为0x1,%RCX;
JNE startofloop;);
}
这个程序编译罚款,但在运行时,它出现segfaults初始 MOVQ
指令。
我必须缺少明显的东西,但我希望这里有人能指出来给我。
我运行在Debian 8内核3.16.0-4-amd64的,在相关情况。
对于未来的参考,这是编译器生成的。
主:
.LFB0:
.cfi_startproc
pushq%RBP
.cfi_def_cfa_offset 16
.cfi_offset 6,-16
MOVQ%RSP,RBP%
.cfi_def_cfa_register 6
#APP
#2asm_fail.c1
MOVQ 0x5F5E100,RCX%; startofloop:;子为0x1,%RCX; JNE startofloop;
#0,2
#NO_APP
原来,它已经太长时间,因为我已经写了ASM,我忘记了与<$ C $一绝preface立即值C> $ 在AT&amp; T公司的语法。我发现提醒时仔细检查AT&amp; T公司语法。
ASM(MOVQ $ 100000000,RCX%;
startofloop:;
子$为0x1,%RCX;
JNE startofloop;);
Consider the following short program.
int main(){
asm("movq 0x5F5E100, %rcx;"
"startofloop: ; "
"sub 0x1, %rcx; "
"jne startofloop; ");
}
This program compiles fine, but when it is run, it segfaults on the initial movq
instruction.
I must be missing something obvious, but I hope someone here can point it out for me.
I am running on Debian 8, with kernel 3.16.0-4-amd64, in case that is relevant.
For future reference, this is what the compiler generated.
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
#APP
# 2 "asm_fail.c" 1
movq 0x5F5E100, %rcx;startofloop: ; sub 0x1, %rcx; jne startofloop;
# 0 "" 2
#NO_APP
It turns out that it has been too long since I have written asm, and I had forgotten that one must preface immediate values with $
in AT&T syntax. I found the reminder here when double-checking AT&T syntax.
asm("movq $100000000, %rcx;"
"startofloop: ; "
"sub $0x1, %rcx; "
"jne startofloop; ");
这篇关于段错误的指令MOVQ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!