CompOrg Fall 2003 Homework #4 FAQ


Homework #4 FAQ

Question:

Should it be possible to use your "/bin/ls" execing program/string just to test things out?

Answer:

Yes, the sample code that execs ls should work, as long as the stack has room to handle the stuff that program pushes on the stack (before issuing the call to exec). So - you may need to move the stack pointer away from the program (add $-1000,%esp should do it). You still need to worry about setting the return address appropriately (to point to whatever program you put in the string).

   
Question:

call doesn't seem to be working, it jumps to a different location than the one I give it (when I try to call credit_account).

Answer:

call and jmp (all the jump instructions) are pc-relative. This means that the assembler actually specifies the destination address as an offset from the value in %eip. So you can't put something like:

call 0x0812345

in your assembly code. You can use indirect call or jump instructions (remember how a switch statement jumps to the right place in a call table?). So get the right address in a register and you can do this: call *%eax.