variadic function and wrong stack address
Posted: Tue Dec 25, 2012 5:47 pm
hey,
i'm trying to implement a printf function.
here is some code :
what I get in eax on the breakpoint is 0x6ffec. Actually, the variable is located at 0x7ffec. The stack segment start at 0x10000 and the data segment start at 0. So why don't I get the true address of the stack? obviously the va_arg macro get me a wrong value then...
Thanks
i'm trying to implement a printf function.
here is some code :
Code: Select all
void printf(const char *s, ...)
{
unsigned int ptr = (unsigned int)(&s);
_asm
{
push eax
mov eax, ptr
XCHG BX, BX // breakpoint here
pop eax
}
va_list vl;
va_start(vl, s);
while (*s)
{
if(*s == '\n')
{
text_cursor += (160 - (((unsigned int)text_cursor - 0xB8000) % 160));
s++;
continue;
}
if (*s == '%')
{
if (*(s + 1) == '%')
s++;
else
{
if(*(s + 1) == 'i')
printValue(va_arg(vl, int));
else if(*(s + 1) == 's')
printf(va_arg(vl, char*));
s += 2;
continue;
}
}
*text_cursor++ = *s++;
*text_cursor++ = 0x07;
}
}
Thanks