previous | start | next

Problem 3.5

You are given the following information. A function with prototype

void decode1(int *xp, int *yp, int *zp);
   

is compiled into assembly code. The body of the code is as follows:

1 movl 8(%ebp),%edi
2 movl 12(%ebp),%ebx
3 movl 16(%ebp),%esi
4 movl (%edi),%eax
5 movl (%ebx),%edx
6 movl (%esi),%ecx
7 movl %eax,(%ebx)
8 movl %edx,(%esi)
9 movl %ecx,(%edi)
   

Parameters xp, yp, and zp are stored at memory locations with offsets 8, 12, and 16, respectively, relative to the address in register %ebp.

Write C code for decode1 that will have an effect equivalent to the assembly code above.

You can test your answer by compiling your code with the -S switch. Your compiler may generate code that differs in the usage of registers or the ordering of memory references, but it should still be functionally equivalent.



previous | start | next