Sunday, March 1, 2020

Hello World sample code in MIPS assembly

This is a demonstration "Hello World" sample code in MIPS assembly. Launch EzMIPS, copy the following MIPS code and paste it into EzMIPS. Assemble, Run.


# ---------- "Hello World" in MIPS assembly ------------- #


# All variables are placed after the .data directive      #
.data

# The .asciiz assembler directive creates an ASCII string #
# in memory terminated by the null character. Note that   #
# strings are surrounded by double-quotes                 #

msg:  .asciiz "Hello World!\n"

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

# All program code is placed after the .text directive    #
.text

# Declare main as a global function
.globl main

# The label 'main' represents the starting point
main:

# ...................................................... #
    # Run the print string syscall which has code 4
    
    li $v0, 4     # Code for syscall: print_string
    la $a0, msg   # load the address of msg
    syscall

# ...................................................... #
    
    li $v0, 10    # Code for syscall: exit program
    syscall

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


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

Regards,

Antonis

No comments:

Post a Comment