[英]Switch statement assembly code to c
I am having a very hard time reverse engineering a switch statement from assembly code into a C program.我很难将 switch 语句从汇编代码逆向工程为 C 程序。
.file
"switch_prob2-soln.c"
.text
.globl switch_prob
.type switch_prob, @function
switch_prob:
.LFB0:
.cfi_startproc
subq $60, %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,8), %rax
ret
.L4:
movq %rdi, %rax
sarq $3, %rax
ret
.L5:
movq %rdi, %rax
salq $4, %rax
subq %rdi, %rax
movq %rax, %rdi
.L6:
imulq %rdi, %rdi
.L2:
leaq 75(%rdi), %rax
ret
.cfi_endproc
.LFE0:
.size switch_prob, .-switch_prob
.ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
.section .note.GNU-stack,"",@progbits
Here is the basic C program that I have:这是我拥有的基本 C 程序:
long switch_prob(long x, long n)
{
long result = x;
switch(n) {
}
return result;
}
All that I asking for is helpful advice to get started.我所要求的只是有用的开始建议。 I know I can compile with -S or -O1.
我知道我可以用 -S 或 -O1 编译。 Thank you for your time.
感谢您的时间。
This is what my c code displays in assembly这是我的 c 代码在汇编中显示的内容
here is my c code这是我的 c 代码
if anyone can help me please it will be awesome, I am trying to get the quad to show 3 2 3 4 5 6如果有人可以帮助我,那就太棒了,我正在尝试让四边形显示 3 2 3 4 5 6
It's unclear what you have the problem with.目前还不清楚你有什么问题。 I hope you know it uses a jump table.
我希望你知道它使用跳转表。
It should be obvious that you have 6 cases and a default, with some sharing code.很明显,您有 6 个案例和一个默认值,并带有一些共享代码。 The instructions are quite simple, I trust you have no problem with those.
说明很简单,我相信你对这些没有问题。
As for the switch expression itself, it's just a trivial transformation done by a single instruction.至于 switch 表达式本身,它只是由单个指令完成的微不足道的转换。
I tried not to give away the solution, you asked for advice to get started after all.我尽量不放弃解决方案,毕竟你是征求意见才开始的。 Do you need any more hints?
你需要更多提示吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.