0

I'm new to assembly and I'm doing this for school. It's segfaulting on line 16 (cmpq) even though from what I understand I'm doing this correctly. Thanks in advance.

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

Edit: Shoutout to lurker and Nate in the comments. Thanks!

briefchase
  • 11
  • 2
  • What is your question? Also, if you want debugging help, please post a [mcve]. Right now, your code cannot be compiled and ran as is and I have no idea what arguments you call it with. Please add enough code such that any reader can reproduce your issue on his own computer. – fuz Apr 03 '20 at 02:32
  • 3
    Your 63 is accessing memory location 63 (which is an access violation), not the literal number 63. Look at your references to zero for a proper example. – lurker Apr 03 '20 at 02:35
  • 1
    Also, inspect your push/pops carefully, and look again at what the calling conventions say about caller/callee saved registers. – Nate Eldredge Apr 03 '20 at 02:59

0 Answers0