# # This is the template given for assignment 3. Your job is to fill in the # exp code, which must be a subroutine. (No call to a mult function is # needed.) # # # Main template by bsy@cs.ucsd.edu, Oct 20, 1997. # # C code for the main loop is roughly: # # for (;;) { # int t; # putstr("input x (negative to quit): "); # t = getnum(); # if (t < 0) break; # x = t; # putstr("input y (negative to quit): "); # t = getnum(); # if (t < 0) break; # y = t; # t = exp(); # putstr("x^y = "); putnum(t); # } # return 0; # # # Prompts and output strings for I/O loop. # .data xprompt: .asciiz "input x (negative to quit): " yprompt: .asciiz "input y (negative to quit): " resultstr: .asciiz "x^y = " newline: .asciiz "\n" .text main: sub $sp,$sp,8 sw $fp,4($sp) add $fp,$sp,8 sw $ra,0($fp) # # No local variables on the stack frame. Don't worry about # this; we'll go over it in class. For now, your function # gets its input parameters via global variables. # again: # prompt loop for input values la $a0,xprompt # prompt for x li $v0,4 syscall li $v0,5 # input x syscall blt $v0,0,quit # negative x quits sw $v0,x la $a0,yprompt # prompt for y li $v0,4 syscall li $v0,5 # input y syscall blt $v0,0,quit # negative y quits sw $v0,y jal exp move $s0,$v0 la $a0,resultstr # print result li $v0,4 syscall move $a0,$s0 li $v0,1 syscall la $a0,newline li $v0,4 syscall j again quit: lw $ra,0($fp) lw $fp,4($sp) add $sp,$sp,8 li $v0,0 # main returns 0 as exit status jr $ra # # exp: inputs: x,y, both non-negative. # output: $v0 == x^y. # # # exp parameters # .data x: .word 0 y: .word 0 .text exp: # your code goes here li $v0,5 # this is obviously wrong, but # allows you to load this code and # test out running xspim jr $ra