I'm reviewing a practice midterm at the moment. the question gives a piece of assembly code (IA32) and instructs to write the C equivalent of it. Just want to make sure I'm doing it correctly. Thanks!
Assembly program given:
.global _someOperation _someOperation: pushl %ebp movl %esp, %ebp movl 8(%ebp), %ebx movl 12(%ebp), %edx decl %edx xorl %esi, %esi movl (%ebx, %esi, 4), %eax continue: incl %esi cmpl (%ebx, %esi, 4), %eax jl thelabel movl (%ebx, %esi, 4), %eax thelabel: cmp %esi, %edx jne continue movl %ebp, %esp popl %ebp ret This is the code I've written:
void someOperation(int *num, int count) //Given { int k; //Given count--; int i = 0; k = num[i]; i++; while(count != i) { if(k >= num[i] k = num[i]; i++; } return (k); }
gcc -m32 -S file.cto see what comes out. You'll notice your code has a syntax error, and avoidfunction returning a value.