Reputation: 1259
I am working on function calls and returns in x86 assembly. I can't seem to get this to go without crashing. I am calling the function MIRROR_BYTE from bit_operations. But every time i run the code it has unknown error and crashes. It happens only after I MIRROR_BYTE finishes Really lost here, any help is appreciated. url to full code
__declspec(naked) void
bit_operations(unsigned long inputDWord, unsigned long *outputDWord)
{
__asm{
// start code for part B here
push eax
push ebx
mov ebx, [esp + 12]
push ebx //move inputDword into the stack
call MIRROR_BYTE
pop ebx //pop inputDword out of the stack
pop ebx
pop eax
// end code for part B here
ret
}
}
/*
This function takes 4 bytes as input and mirrors the value of Byte 4 (leftmost).
For example, for a byte like 10110111, the mirrored byte value is 11101101.
*/
__declspec(naked) unsigned long
MIRROR_BYTE( unsigned long inputDWord )
{
__asm{
// not sure what to do here just return dummy al from inputDword
mov al, byte ptr[esp +4]
}
}
Upvotes: 0
Views: 1194
Reputation: 5884
You need to return from MIRROR_BYTE!!! Without a ret
or C return, the CPU will continue executing code after the MIRROR_BYTE proc.
Upvotes: 1
Reputation: 58762
Notice that your pop eax; pop ebx
should be reversed to match the push eax; push ebx
earlier. Can't say if that's causing your problems, though.
Upvotes: 0