Sunday, March 29, 2020

trap, break, jalr and jr MIPS instructions

This is sample MIPS assembler code demonstrating the behaviour of the teq, teqi, tge, tgeu, tgei, tgeiu, tlt, tlti, tltiu, tltu, tne, tnei, jr, jalr, lw, sw, break instructions. These instructions were implemented and/or improved in EzMIPS v.9.1.0. The code is fully commented.

Launch EzMIPS, copy the following MIPS code and paste it into EzMIPS, the MIPS assembler editor & simulator. Assemble, Run.


# teq, teqi, tge, tgeu, tgei, tgeiu, tlt, tlti, tltiu, tltu, tne, tnei, jr, jalr, lw, sw, break

main:

# ................................................................ #

    #break           # Runtime exception at 0x00400000: break instruction executed; code: 0
    #break 192       # Runtime exception at 0x00400000: break instruction executed; code: 192
    #break 0x08      # Runtime exception at 0x00400000: break instruction executed; code: 8
    #break 0x123  6  # invalid <break> instruction syntax

# ................................................................ #
    
    #la $ra, end
    #addi $ra, $ra, 1
    #jr $ra          # invalid program counter <0x00400011>

# ................................................................ #

    #li $5, 0x00400001
    #jalr $5         # invalid program counter <0x00400001>

# ................................................................ #

    #jalr $6, $7     # invalid program counter <0x00000000>
    
# ................................................................ #

    # following 2 lines used to crash in previous versions, fixed!
    #lw
    #sw

# ................................................................ #

    # following line used to crash in previous versions, fixed!
    # lw $10, 4($t7)

# ................................................................ #

    #lw $11, N      # should be ok, yes it is!
    #lw $11, main   # <main> is an uknown variable name

# ................................................................ #

    # Runtime exception: Cannot read directly from this address <0x00400000>
    #la $10, main
    #lw $11, ($10)

# ................................................................ #

    # Error | Runtime exception: Cannot write directly to this address <0x00000004>
    #sw $10, 4($t7)

# ................................................................ #

    #teq $12, $20   # Error | line 55    | Runtime exception (trap) at <0x00400000>

    #li $13, -10
    #teqi $13, -10  # Error | line 58    | Runtime exception (trap) at <0x00400008>

    #li $14, 0xffffffff
    #li $15, 0
    #tge $14, $15         # should NOT trap
    #tgeu $14, $15        # should TRAP

    #li $18, -1
    #tgei $18, 1          # should NOT trap
    #tgeiu $18, 1         # should TRAP
    
    #li $14, 0
    #li $25, -1
    #tlt $14, $25         # should NOT trap
    #tltu $14, $25        # should TRAP

# .............................................................. #

    #tlti $0, -1          # should NOT trap
    #tltiu $0, -1         # should TRAP

# .............................................................. #

    #li $14, 123
    #li $15, 124
    #tne $14, $15         # should TRAP
    #tnei $14, 128        # should TRAP

# .............................................................. #

end:
    sll $0, $0, 0

    #sync

.data

Y: .word 0xff
N: .word 0x14

# ................................................................ #

Please let me know of any suggestions or bugs regarding the code above.

Regards,

Antonis

No comments:

Post a Comment