首页 > 解决方案 > 使用 cmp x84 时出现段错误

问题描述

我是组装新手,我正在为学校做这个。它在第 16 行(cmpq)上出现段错误,尽管据我了解我这样做是正确的。提前致谢。

global transitions
.text
transitions:
push %rbp #Push old frame pointer to stack
movq %rsp, %rbp #Update rbp so that its pointing at the old rbp (which is the bottom of the new frame)
pushq %r12 #save r12
pushq %r13 #save r13
pushq %rax #save return value

movq $0, %r12  #set shift count to 0
movq $0, %rax #set transitions to 0
movq %r13, %rdi #copy perameter
shlq %r13 #Initialize carry flag
start:
incq %r12 #Increment shifts
cmpq %r12, 63 #See if shift count is greater than 63
jns end #Jump to end if true
shl %r14 #Shift left
jnc start #Jump to start if bit was 0
incq %r12 #Increment shifts
cmpq %r12, 63 #See if shift count is greater than 63
jns end #Jump to end if true
shl %r14 #Shift left
jnc found #See if sequence is found
jmp start#Jump to start
found:
incq %rax #increment transitions
end:
pop %r14
pop %rax
pop %r13
pop %r12
ret

编辑:在评论中向潜伏者和内特大喊。谢谢!

标签: linuxassemblyx86mov

解决方案


推荐阅读