Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: compile other MIPS programs #2726

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,7 @@ generate-doc:
@echo "The documentation is available at: ./target/doc"
@echo ""

o1vm-test:
@mips-linux-gnu-as -o ./o1vm/resources/programs/hello_world.bin ./o1vm/resources/programs/hello_world.mips

.PHONY: all setup install-test-deps clean build release test-doc test-doc-with-coverage test test-with-coverage test-heavy test-heavy-with-coverage test-all test-all-with-coverage nextest nextest-with-coverage nextest-heavy nextest-heavy-with-coverage nextest-all nextest-all-with-coverage format lint generate-test-coverage-report generate-doc
38 changes: 38 additions & 0 deletions o1vm/resources/programs/hello_world.mips
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
main:
# Initialise
addu $t1, $zero, 1 # Initial 0
addu $t2, $zero, 1 # Initial 1
addu $t4, $zero, 5 # Counter
addu $t5, $zero, 1 # Constant
loop:
addu $t3, $t1, $t2 # Add
xor $t1, $t2, $zero # Write t2 to t1
xor $t2, $t3, $zero # Write t3 to t2
subu $t4, $t4, $t5 # Decrement counter
bne $t4, $zero, loop # Backward branch
beq $t4, $zero, exit # Forward branch
nop # Padding for forward branch
nop
nop
exit:
li $v0, 10 # Sets $v0 to "10" to select exit syscall
syscall # Exit

other_test:
sub $t5, $t2, $t3 # Subtract
sw $t5, Z # Store the answer in Z (declared at the bottom)

# Run the print_string syscall which has code 4
li $v0,4 # Code for syscall: print_string
la $a0, msg # Pointer to string (load the address of msg)
syscall
sw $0, msg
la $a0, msg2 # Pointer to string (load the address of msg)
j $a0
syscall

.data
value: .word 12
Z: .word 0
msg: .asciiz "Hello World!\n"
msg2: .asciiz "Hello World again!\n"
Loading