Strange behavior with -bare option

Bug #393072 reported by Fratelli
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
spim (Ubuntu)
New
Undecided
Unassigned

Bug Description

Binary package hint: spim

Ubuntu: Ubuntu 8.10
Spim: 7.4-0ubuntu1

When tested with the -bare option, the following code could will produce a result of 0xCAFE for $t0 and 0x03 for $t1. Yet, with a simple analysis of the code, it is clear that it's impossible to have both at the same time. My claim is sustained by the fact that after the beq instruction is triggered, the delay slot is already being executed, therefore j is also triggered. But the ori $t0, $zero, 0xCAFE statement should not be triggered (in j's delay slot) if the jump was made to endbeq. Both cannot happen. Best regards.

  .text
  .globl main

main: ori $t0, $zero, 0xFACE
  ori $t1, $zero, 0x0000
  beq $zero, $zero, endbeq
  j endj
  ori $t0, $zero, 0xCAFE

endbeq: ori $t1, $t1, 0x01
endj: ori $t1, $t1, 0x02

Revision history for this message
Mackenzie Morgan (maco.m) wrote :

The author has been told about this bug.

Revision history for this message
James Larus (larus) wrote :

Bizarre as it may seem, according to my reading of the MIPS manual, SPIM is correct: $t0 contains CAFE and $t1 contains 3. It would be great if someone who had a working R2000/R3000 would try this and confirm the outcome (does anyone still have a working machine?).

Here's the relevant description from the MIPS manual:
"Branch instructions are delayed and do not take effect until after one or more instructions immediately following the Branch instruction have been executed. The instruction or instructions in this branch delay slot are **always** executed." (p. 1-9) And, yes, the jump instruction is considered a branch instruction.

The R2000 was a simple machine, with a wonderful regularity, even when it didn't make a lot of sense from a programmer's point of view.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.