I have this x86 assembler code and am trying to convert it to C:
.GLOBAL calculate calculate: pushl %ebp movl %esp,%ebp movl 12(%ebp),%eax movl 8(%ebp),%ecx cmpl $2,%ecx ja done jmp *operations(,%ecx,4) operation1: imull %eax,%eax jmp done operation2: negl %eax jmp done operation3: addl $0x80,%eax done: leave ret operations: .long operation1, operation2, operation3
My question is about the jmp *operations(,%ecs,4) . I think this is a switch statement, and I know how it works in memory, but how does this translate to C? Shouldn't I have known what was on the stack in these places to write a switch for it?
This is what I have:
int calculate(int a, int b) { if (2 > a) { return b; } switch(a) { case : b = (b * b); break; case : b = (b * -1); break; case : b = (b + 128); break; } return b; }
source share