简体   繁体   English

尝试添加值时出现x86_64程序段分段错误

[英]x86_64 Assembly Segmentation Fault when trying to add value

I keep getting a segmentation fault error immediately after I use an addq instruction; 使用addq指令后,我立即收到分段错误错误; the code is fine before I implement the instruction. 在执行指令之前,代码很好。

.data
insn_count:
    .long 0
str:
    .string "test"

bubble_sort:
.LFB2:
 addq $3,insn_count
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movq %rdi, -24(%rbp)
movl %esi, -28(%rbp)
movl $0, -4(%rbp)
jmp .L2

That's a sample portion of my code. 这是我的代码的示例部分。 I can't seem to pinpoint what the issue is; 我似乎无法查明问题所在。 can anyone help? 有人可以帮忙吗? I have also tried defining insn_count using the .long directive but I still get the same error. 我也尝试使用.long指令定义insn_count,但仍然出现相同的错误。

I'm not familiar with this assembly syntax, but seems, that "addq $3,insn_count" is trying to add 3 to address of insn_count not to it's value. 我不熟悉此汇编语法,但似乎“ addq $ 3,insn_count”正尝试将3添加到insn_count的地址中而不是它的值。 Because of that you could have segmentation fault. 因此,您可能会遇到细分错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM