MIPS Assembly Language Programming
MIPS stands for “Microprocessor without interlocking pipeline stages”. MIPS processor is used in Sony, Cisco Routers, Laser Printers and so much more.
Assembly Language Programming is a low level programming. One of the benefits of learning to code Assembly Language is that it will help you gain new insights into how to write more effective high level programs.
Suppose you want to write a MIPS program that asks a user for a number and then the program adds all of the numbers before the input number.
.dataPrompt: .asciiz "\n Please input value for N = "
Result: .asciiz "The sum of integers from 1 to N is "
Bye: .asciiz "\n *** Thank you- Have a good day***"
.globl main
.text
main:
li $v0, 4 # system call code for Print String
la $a0, Prompt # load address of prompt into $a0
syscall # Print the prompt message
li $v0, 5 # System call code for Read Integer
syscall # reads the value of N into $v0
blez $v0, End # branch to end if $v0 < = 0
li $t0, 0 # clear register $t0 to 0Loop:
add $t0, $t0, $v0 # sum of integers in register &t0
addi $v0, $v0, -1 # summing integers in reverse order
bnez $v0, Loop # branch to loop if $v0 is != 0
li $v0, 4 # system call code for Print String
la $a0, Result # load address of message into $a0
syscall # Print the string
li $v0, 1 #system call code for Print Integer
move $a0, $t0 # move value to be printed to $a0
syscall # Print sum of integers
b main # branch to main
End:
li. $v0, 4 #system call code for Print String
la $a0, Bye # load address of msg. into $a0
syscall # print the string
li. $v0, 10 # terminate program run and
syscall #return control to system
The code above asks the user for a number and then returns the sum of all of the numbers that come to the number written.
The code has, main
, loop
then end
which ends the program. We can see that high level languages that come after assembly language programs follow the same structure as Assembly Language.