4

I am coding a program that uses interrupt handling to play an ascii-based game in MIPS. I am told to "Long call" my main function from my handler. My handler takes place under .ktext 0x80000180 and looks like this:

.ktext  0x80000180

    move    $k1, $at

    beq $13, 0, keyboard
    li  $v0, 10 # Do nothing and exit
    syscall

    keyboard: # else check interupt level
    la  $t9, 0xffff0000
    beq $t9, 1, continue

    li  $v0, 10     # Do nothing and exit
    syscall
    continue:

    jal frogger     # call frogger function
    mtc0    $0, $13     # set cause register to 0

    mfc0    $k0, $12        # Fix status register
    andi    $k0, 0xfffd # clear EXL bit
    ori $k0, 0x1        # Enable interrupts
    mtc0    $k0, $12        # Store value back into status register


    move    $at, $k1

    eret

The problem is with the line jal frogger, it says Error in F:\Users\Matt\WSU\Cpts 260\HW9\HW9.asm line 32: Jump target word address beyond 26-bit range.

Is it something wrong with the rest of the code or is there a special way to call a function from the .ktext?

Thanks!

Matt Hintzke
  • 7,744
  • 16
  • 55
  • 113

3 Answers3

5

A long call uses the full (32-bit) address of the target. This is different from your jal call which can only encode 26 bits of address in the instruction and might be PC-relative (I don't remember whether this is the case or not). To do a long call, you would construct or load the address to a register and then branch to that.

Variable Length Coder
  • 7,958
  • 2
  • 25
  • 29
  • I think one of the differences between dlx and mips is one uses absolute and the other pc-relative. – old_timer Dec 14 '12 at 01:11
  • MIPS `jal` replaces the low *28* its of PC with a new value. MIPS instructions are word-aligned so the 26-bit immediate is left shifted by 2. This makes it region-absolute, within the same 256MiB region as the branch delay slot. [How to Calculate Jump Target Address and Branch Target Address?](https://stackoverflow.com/q/6950230) – Peter Cordes Oct 25 '20 at 00:32
5

Replace jal frogger by something like:

  la    $t9, frogger
  jalr  $t9

JALR uses an absolute address in MIPS.

markgz
  • 6,054
  • 1
  • 19
  • 41
0

I had the same issue. I figured out that my function was being defined in the .data section. Once I put it under the .text section, it ran perfectly fine.

Also, I'm brand new to MIPS so idk what .ktext is. Sorry I can't help there.

abhinav3414
  • 946
  • 3
  • 9
  • 31
  • That's *not* the same issue then. This is about calling functions that are (or might be) in a different 256MiB region of memory (different high 4 bits of address, which `jal` leaves unmodified). [How to Calculate Jump Target Address and Branch Target Address?](https://stackoverflow.com/q/6950230) – Peter Cordes Oct 25 '20 at 00:33