2
votes

I looked online, but the only thing I was able to find was this syntax PI = 3.1415, but for some inexplicable reason this does not work in the MIPS simulator program I'm using which is MARS 4.5. I presume it should work if it's part of the MIPS language specification. When trying to assemble a simple hello world program, the compiler says that I've got an invalid language element in my code. Here's the code itself:

################################################################################
#                                                                              #
# This is a hello world program in the MIPS assembly language. It prints out   #
# "Hello, World!" on the screen and exits.                                     #
#                                                                              #
################################################################################

# System call code constants
SYS_PRINT_STRING = 4
SYS_EXIT         = 10

.data
    msg: .asciiz "Hello, World!\n"

.text
.globl __start
__start:
    la $a0, msg              # Load the address of the string "msg" into the
                             # $a0 register
    li $v0, SYS_PRINT_STRING # Store the system call for printing a string on
                             # the screen in the $v0 register
    syscall

    li $v0, SYS_EXIT         # Store the system call to exit the program in the
                             # $v0 register
    syscall
1

1 Answers

8
votes

What you want is a substitution macro. MIPS is an instruction set, it doesn't define much beside the instructions themselves. Instructions sets usually don't have a concept of named constants like higher level languages do. Substitution macros are implemented by the assembler, so you need to check your assembler documentation.

For MARS, the directive is .eqv. Example :

.eqv SYS_PRINT_STRING 4

li $v0, SYS_PRINT_STRING