1

Let me preface this by saying that I'm new to MIPS.

I'm trying to reverse some sample code that I compiled for PSX using Psy-Q. I compiled a small "hello world" program that happens to contain the following function call in C

int main() {
    FntLoad(960, 256) // load the font from the BIOS into the framebuffer
}

I suppose it doesn't matter too much what the function call is, but it is that line above with those two arguments.

My disassembly looks like the following for that function call in hexadecimal:

C0 03 04 24 E7 45 00 0C 00 01 05 24

In my disassembler, it looks like the following 3 instructions:

TEXT:800103E4                     li      $a0, 0x3C0
TEXT:800103E8                     jal     FntLoad
TEXT:800103EC                     li      $a1, 0x100

Out of the examples that I've seen so far, all function arguments are loaded before the jal line, but in my disassembly the load immediate happens after the jump.

Is this correct or is something weird going on here? If my understand of how jal is incorrect, would someone mind explaining how the last argument is passed?

Ci3
  • 4,632
  • 10
  • 34
  • 44
  • You have discovered the [Branch Delay Slot](https://stackoverflow.com/questions/15375084/what-is-the-point-of-delay-slots). – Raymond Chen Dec 11 '18 at 00:17
  • @RaymondChen Wow it makes sense. If you simply put that as an answer I will accept it. – Ci3 Dec 11 '18 at 00:19
  • 1
    Possible duplicate of [What is the point of delay slots?](https://stackoverflow.com/questions/15375084/what-is-the-point-of-delay-slots) – Raymond Chen Dec 11 '18 at 01:56
  • Does this answer your question? [Why do MIPS compilers put an instruction after the "j" that returns from a function? It gets executed?](https://stackoverflow.com/questions/59130450/why-do-mips-compilers-put-an-instruction-after-the-j-that-returns-from-a-funct) – phuclv Dec 02 '19 at 06:10

0 Answers0