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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…