Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What architecture are you programming for? </p> <p>If you are writing a boot loader for x86, then your boot loader will at first be in 16 bit mode. Thus when the compiler issues a push instruction, which is how I would guess it passes the arguments for the printf() function, it will by default push 16 bits of data. The long data type will be a specially issued instruction (or two) to push all 32 bits onto the stack, this is assuming an int is 16 bits and a long is 32 bits (which for a 16bit mode compiler, is not an unreasonable assumption, I don't think).</p> <p>So, lets assume x86 in 16 bit mode:</p> <p>It would appear you are using *ip to address the arguments as they are pushed on the stack. Since ip is a pointer to a long (a 32 bit data type) when you do ip++ you are incrementing the actual value held by the pointer by 4, as in if *ip = 0x1234 then *(ip+1) = 0x1238. Thus if you are using ip++ for the 16bit ints, then you are skipping an int every time you do ip++, since ints are only 2 bytes (16 bits). A possible solution is to use void * for ip and then add sizeof(data type) to ip; i.e if you print an int, so an:</p> <pre><code>void *ip = &amp;(fmt + 1); /* Skip over fmt. */ ... ip += sizeof(int); </code></pre> <p>Or for an unsigned long:</p> <pre><code>ip += sizeof(unsigned long); </code></pre> <p>However, without more specific details about the exact architecture you are programming for and and what ABI your compiler is using, I can only wildly speculate.</p> <p>I hope this helps.</p> <p>Regards, Alex</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload