switch语句汇编代码转c
Switch statement assembly code to c
我很难将 switch 语句从汇编代码逆向工程到 C 程序中。
.file
"switch_prob2-soln.c"
.text
.globl switch_prob
.type switch_prob, @function
switch_prob:
.LFB0:
.cfi_startproc
subq , %rsi
cmpq , %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 , %rax
ret
.L5:
movq %rdi, %rax
salq , %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
这是我的基本 C 程序:
long switch_prob(long x, long n)
{
long result = x;
switch(n) {
}
return result;
}
我所要求的只是有用的入门建议。我知道我可以使用 -S 或 -O1 进行编译。谢谢你的时间。
这是我的 C 代码在汇编中显示的内容
这是我的 C 代码
如果有人能帮助我,那就太棒了,我正在努力让四边形显示
3个
2个
3个
4个
5个
6
不清楚您遇到了什么问题。我希望你知道它使用跳转 table.
很明显你有 6 个案例和一个默认值,还有一些共享代码。说明很简单,相信你不会有问题的。
至于 switch 表达式本身,它只是一条指令完成的微不足道的转换。
我尽量不放弃解决方案,毕竟你问的是入门的建议。您还需要更多提示吗?
我很难将 switch 语句从汇编代码逆向工程到 C 程序中。
.file
"switch_prob2-soln.c"
.text
.globl switch_prob
.type switch_prob, @function
switch_prob:
.LFB0:
.cfi_startproc
subq , %rsi
cmpq , %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 , %rax
ret
.L5:
movq %rdi, %rax
salq , %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
这是我的基本 C 程序:
long switch_prob(long x, long n)
{
long result = x;
switch(n) {
}
return result;
}
我所要求的只是有用的入门建议。我知道我可以使用 -S 或 -O1 进行编译。谢谢你的时间。
这是我的 C 代码在汇编中显示的内容
这是我的 C 代码
如果有人能帮助我,那就太棒了,我正在努力让四边形显示 3个 2个 3个 4个 5个 6
不清楚您遇到了什么问题。我希望你知道它使用跳转 table.
很明显你有 6 个案例和一个默认值,还有一些共享代码。说明很简单,相信你不会有问题的。
至于 switch 表达式本身,它只是一条指令完成的微不足道的转换。
我尽量不放弃解决方案,毕竟你问的是入门的建议。您还需要更多提示吗?