Wednesday, November 11, 2009

a + b in MIPS assembly

We're just starting to learn assembly at college, so here's my first program. It reads to numbers, sums them up and displays the result. Not really rocket science, but good for a first program without any previous practice: .data prompt1: .asciiz "a: " prompt2: .asciiz "b: " newline: .asciiz "\n" .text main: # print prompt 1 li $v0, 4 la $a0, prompt1 syscall # read in $t0 li $v0, 5 syscall move $t0, $v0 #print prompt 2 li $v0, 4 la $a0, prompt2 syscall # read in $t1 li $v0, 5 syscall move $t1, $v0 # $a0 = $t0 + $t1 add $a0, $t0, $t1 # print result li $v0, 1 syscall # newline li $v0, 4 la $a0, newline syscall # exit li $v0, 10 syscall References:

No comments:

Post a Comment