Thursday, February 27, 2020

MIPS jal and jr instructions

This is demonstration sample code of jal and jr MIPS instructions. Launch EzMIPS, copy the following MIPS code and paste it into EzMIPS. Assemble, Run.

# -------- demonstration of jal and jr instructions -------- #

.data
szMessage: .ascii  "- Hello world!\n- Are you ok?\n"
           .asciiz "- Yes\n- Oh, my God!\n"

.text


# ---------------------------------------------------------- #
main: 
    
    jal print           # save pc in $ra & jump to print
    jal delay           # save pc in $ra & jump to delay
    
# ---------------------------------------------------------- #
    
    li $v0, 10
    syscall             #exit the program gracefully
    
# ---------------------------------------------------------- #
print:
    
    la $a0, szMessage
    li $v0, 4
    syscall             # print string
    jr $ra              # return to caller

# ---------------------------------------------------------- #
delay:
    
    sll $zero, $zero, 0
    sll $zero, $zero, 0
    sll $zero, $zero, 0
    jr $ra              # return to caller

# ---------------------------------------------------------- #


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

Regards,

Antonis

No comments:

Post a Comment