Mips Assembly Language Syntax

Mips Syntax is pretty similar to x86 and Arm syntax. Below is the basic syntax of MIPS instruction set:

.data  #Declare or initialize variables
.text
#Here main program goes (Instructions)
#End instruction to terminate the program

.Data Section

In data section variables are declared or initialize. See example below:

.data
msg1: .asciiz  “Enter a value:\n“
msg2: .asciiz  “Sum of value and 100:\n”






(adsbygoogle = window.adsbygoogle || []).push({});



In the above example msg1 and msg2 are the two variables initialized with sting data.

.Text Section

Text section include our main code. See example below:

.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.

Nauman Rehmat
 

Nauman Rehmat is the owner of Assembly Language Tuts.He is interested in Programming and SEO. He is also pursuing a degree in Computer Software Engineering from Comsats.