Mips Syntax is pretty similar to x86 and Arm syntax. Below is the basic syntax of MIPS instruction set:
[code].data #Declare or initialize variables
.text
#Here main program goes (Instructions)
#End instruction to terminate the program
[/code] [thrive_headline_focus title=”.Data Section” orientation=”left”]In data section variables are declared or initialize. See example below:
[code].data
msg1: .asciiz “Enter a value:\n“
msg2: .asciiz “Sum of value and 100:\n”
In the above example msg1 and msg2 are the two variables initialized with sting data.
[thrive_headline_focus title=”.Text Section” orientation=”left”]Text section include our main code. See example below:
[code].text
li $v0,4 # prompt user (print string)
la $a0,msg1 # indicate the message!
syscall
li $v0,5 # read integer, X
syscall
addi $s0,$v0,100 # $s0 = X + 100
li $v0,4 # output message
la $a0,msg2 # indicate the message!
syscall
li $v0,1 # print integer!
move $a0,$s0 # value to print!
syscall
li $v0,10 # exit program!
syscall
Hope you understood the basic Syntax! If there any question let us know in the comment box.