Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird MIPS assembler behavior with jump (and link) instruction
    primarykey
    data
    text
    <p>So, we're studying MIPS architecture at school and we're implementing a MIPS32 architecture. I thought I'd use GNU cross-binutils as assembler but I'm getting weird output when dealing with instructions jal, j and jr. The assembler seems to insert the instructions at the wrong places. I have no idea why this happens, and I doubt the MIPS assembler would be that broken, so I assume this is supposed to happen.</p> <p>Here is my dummy assembly file:</p> <pre><code>.section .text .globl __start __start: addi $a0, $0, 100 addi $a1, $0, 200 jal test test: add $v0, $a0, $a1 jr $ra </code></pre> <p>However, when I disassemble I get this output:</p> <pre><code>Disassembly of section .text: 00000000 &lt;__start&gt;: 0: 20040064 addi a0,zero,100 4: 0c000003 jal c &lt;test&gt; &lt;--- Why is jal coming before addi? 8: 200500c8 addi a1,zero,200 0000000c &lt;test&gt;: c: 03e00008 jr ra &lt;--- Why is jr coming before add? 10: 00851020 add v0,a0,a1 ... </code></pre> <p>Is this some architectural quirk? If so, what is the rationale behind this?</p> <p>EDIT: Tested adding some nop's just for the heck ...</p> <pre><code>.section .text .globl __start __start: addi $a0, $0, 100 addi $a1, $0, 200 nop jal test test: add $v0, $a0, $a1 nop jr $ra </code></pre> <p>and it gives me something that seems somewhat correct.</p> <pre><code>Disassembly of section .text: 00000000 &lt;__start&gt;: 0: 20040064 addi a0,zero,100 4: 200500c8 addi a1,zero,200 8: 0c000004 jal 10 &lt;test&gt; c: 00000000 nop 00000010 &lt;test&gt;: 10: 00851020 add v0,a0,a1 14: 03e00008 jr ra 18: 00000000 nop 1c: 00000000 nop </code></pre> <p>Why are jal and j swapping places with the last instruction?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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