MARS Mips Adding more than 2 registers/printing solution

1

I did a few calculations (not even sure if they're remotely close to accurate as the instructions for the assignment are non existent (thanks worthless professors)) but basically I'm trying to take the value of $t2, $t3, $t4, and $t5.. add them together, then store them in $t6 and print that to the console.

Heres what I have so far

    li $v0,10
    li $t1, 10
    add $t2, $t1, $t1
    sll $t3, $t1, 2
    and $t4, $t1, 0x0000FFFF
    or $t5, $t1, 0x0000FFFF
assembly
integer
mips
add
asked on Stack Overflow Feb 17, 2020 by Brian

1 Answer

1

This should do the job.

    .data ## Data declaration section
    .text ## Assembly language instructions go in text segment
main: ## Start of code section
    add $t1, $t2, $t3 # t1 = t2 + t3
    add $t2, $t4, $t5 # t2 = t4 + t5
    add $t6, $t2, $t1 # t6 = t1 + t2
    move $a0, $t6 # a0 = t6
    li $v0, 1 # system call code to print integer from a0
    syscall # call operating system to perform operation
    li $v0, 10 # terminate program
    syscall

Found the example Hello World! program here: https://courses.cs.vt.edu/cs2506/Fall2014/Notes/L04.MIPSAssemblyOverview.pdf

Which I extended according to your requirements.

This code will output 0 if you run it on MARS simulator, since t2, t3, t4, t5 are 0 basically.

answered on Stack Overflow Feb 17, 2020 by Eraklon • edited Feb 17, 2020 by Eraklon

User contributions licensed under CC BY-SA 3.0