This is a simple MIPS skeleton program that demonstrates some simple MIPS instructions and .data & .text segments. The code is fully documented.
Launch EzMIPS, the MIPS assembler simulator, copy the following MIPS code and paste it into EzMIPS. Assemble, Run.
# Simple MIPS skeleton program: simple instructions, .data & .text #
# ................................................................ #
# Declare main as a global function:
# .globl is an assembler directive that tells the assembler that
# the main symbol will be accessible from outside the current file
# (that is, it can be referenced from other files)
.globl main
# ................................................................ #
# All program code is placed after the .text assembler directive
.text
# The label 'main' represents the starting point
main:
addi $t1, $t1, 1 # Load immediate value 1 into $t1 register
li $t2, 0x25 # Load immediate value 0x25 into $t2 register
# The above is equivalent to:
# ori $t2, $zero, 0x25
lw $t3, value # Load the word stored in value into $t3 = 0x26 = 38
add $t4, $t2, $t3 # $t4 = $t2 + $t3 = 0x25 + 0x26 = 0x4b
sub $t5, $t1, $t3 # $t5 = $t1 - $t3 = 1 - 0x26 = 0xffffffdb = -37
sw $t5, Z # Store the answer in Z (declared at the bottom)
# ................................................................ #
# Exit the program by means of a syscall.
# There are many syscalls - pick the desired one
# by placing its code in $v0. The code for exit is "10"
li $v0, 10 # Sets $v0 to "10" to select exit syscall
syscall # Exit
# The following instructions shoud NOT be executed due to the syscall 10 above!
add $t5, $t5, $t5
add $t5, $t5, $t5
add $t5, $t5, $t5
# .... Memory structures are placed after the .data directive .... #
.data
# The .word assembler directive reserves space in memory for a single 4-byte word
# and assigns that memory location an initial value
value: .word 0x26
Z: .word 0
# ---------------------------------------------------------------- #
Launch EzMIPS, the MIPS assembler simulator, copy the following MIPS code and paste it into EzMIPS. Assemble, Run.
# Simple MIPS skeleton program: simple instructions, .data & .text #
# ................................................................ #
# Declare main as a global function:
# .globl is an assembler directive that tells the assembler that
# the main symbol will be accessible from outside the current file
# (that is, it can be referenced from other files)
.globl main
# ................................................................ #
# All program code is placed after the .text assembler directive
.text
# The label 'main' represents the starting point
main:
addi $t1, $t1, 1 # Load immediate value 1 into $t1 register
li $t2, 0x25 # Load immediate value 0x25 into $t2 register
# The above is equivalent to:
# ori $t2, $zero, 0x25
lw $t3, value # Load the word stored in value into $t3 = 0x26 = 38
add $t4, $t2, $t3 # $t4 = $t2 + $t3 = 0x25 + 0x26 = 0x4b
sub $t5, $t1, $t3 # $t5 = $t1 - $t3 = 1 - 0x26 = 0xffffffdb = -37
sw $t5, Z # Store the answer in Z (declared at the bottom)
# ................................................................ #
# Exit the program by means of a syscall.
# There are many syscalls - pick the desired one
# by placing its code in $v0. The code for exit is "10"
li $v0, 10 # Sets $v0 to "10" to select exit syscall
syscall # Exit
# The following instructions shoud NOT be executed due to the syscall 10 above!
add $t5, $t5, $t5
add $t5, $t5, $t5
add $t5, $t5, $t5
# .... Memory structures are placed after the .data directive .... #
.data
# The .word assembler directive reserves space in memory for a single 4-byte word
# and assigns that memory location an initial value
value: .word 0x26
Z: .word 0
# ---------------------------------------------------------------- #
Please let me know of any suggestions or bugs regarding the code above.
Regards,
Antonis
No comments:
Post a Comment