I am writing my own OS that have its own printf function. In this function I successfully implemented %d, %u, %x, %c and %s parameters, but for some reason analogical (to %d, u, x) code for %p causes invalid opcode exception which means it's either gasm error or UB.
Here's the code:
} else if (*format == 'p') {
format++;
void *p = va_arg(parameters, void*); <-- invalid opcode exception triggers in this
long n = (long) p; line of code (I know from GDB)
char buf[64] = "0x";
itoa64(n, &buf[2], 16);
size_t len = strlen(buf);
tty_puts(buf);
written += len;
} else {
And here's instruction, saved instruction pointer pointed to:
0x202ee2 <printf+866>: pxor %xmm0,%xmm0