

Sltiu at,v0,4 in range of the jump table? The last interesting calling pattern for today is the jump table, commonly used for dense switch statements. In practice, the compiler tends to front-load the fetching of the function pointer.

Lw t6, YYYY(t6) t6 = function pointer from import address table entryĪgain, I put all of the relevant instructions together. Lui t6, XXXX t6 -> 64KB block containing import address table entry

The above example uses t6 and t7 as temporary registers for preparing the call, but in practice, the compiler will use any volatile register that is not being used to pass parameters.Ĭalls to imported functions indirect through the entry in the import address table.
#VISUAL STUDIO 2018 MIPS CODE#
I put all of the virtual dispatch code in one block of contiguous instructions, but in practice the compiler may choose to interleave it with the preparation of the function arguments to avoid data load stalls. Lw t7, n(t6) t7 = function pointer from vtable into a1 through a3, with additional parameters Virtual calls load the destination from the target’s vtable: Note also that the JAL instruction might end up jumping to an import stub if this turns out to have been a naïvely-imported function. The parameters could be set up in any order, and there’s a good chance you’ll find one of the parameters being set up in the branch delay slot. Move a0, s1 parameter 1 copied from another register Move a3, s1 parameter 4 copied from another registerĪddiu a2, sp, 32 parameter 3 is address of local variableĪddiu a1, t1, 1 parameter 2 is calculated in place Sw t0, 20(sp) parameter 5 passed on the stack and additional parameters go on the stack Non-virtual calls generally look like this: If you are debugging through MIPS code, you’ll need to be able to recognize these different types of calling sequences in order to keep your bearings. Okay, now that we see how function calls work, we can demonstrate some common code sequences.
