c - x86 assembly compare operator -


i'm new learning assembly. have assignment reverse engineer switch statement c. bit stuck on part me, seems conditional. variable n passed rsi. question is, when operation n-50 done, value stay in rsi compare operation directly below that? or rsi reset? **note .l7 start of jump table.

subq $50, %rsi cmpq $5, %rsi ja .l2 jmp *.l7(,%rsi,8)  //jump table  l7: .quad .l3 .quad .l2 .quad .l3 .quad .l4 .quad .l5 .quad .l6 .text 

should c code this?

result = n - 50;  if result == 5    goto .l2 else     goto .l7 

or since .ja means jump if above, should be

  result = n - 50;      if result > 5        goto .l2     else         goto .l7 

this full assembly code

.file "switch_prob-soln.c" .text .globl switch_prob .type switch_prob, @function switch_prob: .lfb0: .cfi_startproc subq $50, %rsi cmpq $5, %rsi ja .l2 jmp *.l7(,%rsi,8) .section .rodata .align 8 .align 4 .l7: .quad .l3  .quad .l2 .quad .l3 .quad .l4 .quad .l5 .quad .l6   .text .l3: leaq 0(,%rdi,4), %rax ret .l4: movq %rdi, %rax sarq $2, %rax ret .l5: leaq (%rdi,%rdi,2), %rdi .l6: imulq %rdi, %rdi .l2: leaq 10(%rdi), %rax ret .cfi_endproc .lfe0: .size switch_prob, .-switch_prob 


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -