Page 1 of 1
How to implement SignExtend() function in C ?
Posted: Sun Sep 07, 2008 10:50 am
by kestaz
I looking how to implement SignExtend function in C:
EIP = EIP + SignExtend(Destination);
I read it in intel manuals. Intel manuals has this function explanation but still don't know .. So how ?
Re: How to implement SignExtend() function in C ?
Posted: Sun Sep 07, 2008 10:59 am
by Combuster
What about the explanation don't you get?
Since you're probably talking about emulating some x86 hardware, you basically add a signed byte to an int. Sign extension happens automatically in C once you convert between the correct types.
Re: How to implement SignExtend() function in C ?
Posted: Sun Sep 07, 2008 11:10 am
by kestaz
Just SET most significant byte ?
a = (a & 0x8000) ?
One man do to implement such function like this
unsigned char c ;
signed extended = -c ; ? Does this correct ?
Re: How to implement SignExtend() function in C ?
Posted: Sun Sep 07, 2008 11:12 am
by kestaz
i was not right like this: a |= 0x8000 ;
Re: How to implement SignExtend() function in C ?
Posted: Sun Sep 07, 2008 2:12 pm
by bewing
Code: Select all
void foobar()
{
uint16 i;
int64 s;
i = 45000;
s = (int64) i; // sign extension happens automatically -- s is negative
}
Re: How to implement SignExtend() function in C ?
Posted: Sun Sep 07, 2008 10:34 pm
by kestaz
Ok i wrote this:
void emulator::jcc8(unsigned char rel8)
{
short offset = rel8 ; // sign extended
ip = (ip + offset - 1) & 0xFFFF;
}