Question: #/*# Start of file stack2.a */ # #/*# MIPSMARK 1.0 1/5/98 Copyright 1998 J. Waldron. */ # ## Question: ## The program must sum a

#/*# Start of file stack2.a */ # #/*# MIPSMARK 1.0 1/5/98 Copyright 1998 J. Waldron. */ # ## Question: ## The program must sum a sequence of numbers ## stored on the stack. The word ## on the top of the stack tells you how ## many numbers are in the sequence. ## Do not include this first word in the sum. ## ## Do not rely on the existence on the "test" ## variable, or the code above the ## dashed line. ## #/*# Output format must be: */ #/*# "sum is = 23" */ #include /* for printf in C programs */ #include /* for exit() in C programs */

#/*############################################## # # # text segment # # # #################################################

.text .globl __start __start: # execution starts here */

la $t0,test # This code sets up the stack lw $t1,($t0) # Do not alter add $t0,$t0,4 loop: lw $t2,($t0) sub $sp,$sp,4 sw $t2,($sp) add $t0,$t0,4 add $t1,$t1,-1 bnez $t1,loop la $t0,test lw $t1,($t0) sub $sp,$sp,4 sw $t1,($sp)

# Stack set up now....

#/* Any changes above this line will be discarded by # mipsmark. Put your answer between dashed lines. */ #/*-------------- start cut ----------------------- */

#/* Student's Name: Account: */

#/* j __start #nasty loop if mips program not exited */ #/*-------------- end cut ----------------------- # Any changes below this line will be discarded by # mipsmark. Put your answer between dashed lines.

################################################# # # # data segment # # # #################################################

.data #*/ test: .word 4,6,7,8,2 ans: .asciiz "sum is = " endl: .asciiz " " # #/*# End of file stack2.a */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!