hi
i have a qustion in MIPS program and i need the answer
write a MIPS program that reads an integer x and calculate the sum of integers
x+(x+1)+(X+2)+(x+4)+(x+8) +...... , stop when the sum is greater than 10000 ,
then print the sum and the count of integers included in the sum.
thanks alot ,
11 replies to this topic
#1
Posted 23 May 2011 - 08:13 AM
|
|
|
#2
Posted 23 May 2011 - 03:15 PM
What is your question? Where are you stuck at in your code (feel free to post what you have no matter how simple)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 24 May 2011 - 09:36 AM
We'll gladly help with homework, but we won't do it for you. Do you have pseudocode or at least some idea of what you need to do?
sudo rm -rf /
#4
Posted 24 May 2011 - 10:17 AM
i tried to solve it but i think there's some mistake
and this is which i tried
and this is which i tried
.text main: li $v0,5 syscall move $t0,$v0 li $t0,1 li $t1,2 li, $t2,10000 mul $s1,$t0,2 add $s2,$s0,1 add $s3,$s0,$s2 add $s4,$s4,1 loop: bgt $s3,$t2,l1 la $a0,msg li $v0,4 syscall li $v0,1 move $t2,$s3 syscall la $a0,count li $v0,4 syscall li $v0,1 move $t2,$s4 syscall l1: li $v0,10 syscall .data msg: .asciiz "the sum of integers= \n" count: .asciiz "the count of integers= \n \n" .byte 0
#5
Posted 24 May 2011 - 10:29 AM
A few things:
Your biggest mistake:
You read an integer from the console, put it in $t0, then immediately overwrite $t0 with 1.
Another thing - you forgot the terminating null for your first message:
These are just some things I noticed at a glance. Fix them, then we'll see what happens.
Your biggest mistake:
li $v0,5 syscall [B][COLOR="red"]move $t0,$v0[/COLOR][/B] [B][COLOR="red"]li $t0,1[/COLOR][/B] li $t1,2 li, $t2,10000
You read an integer from the console, put it in $t0, then immediately overwrite $t0 with 1.
Another thing - you forgot the terminating null for your first message:
.data msg: .asciiz "the sum of integers= \n" [B][COLOR="red"].byte 0[/COLOR][/B] count: .asciiz "the count of integers= \n \n" .byte 0
These are just some things I noticed at a glance. Fix them, then we'll see what happens.
sudo rm -rf /
#6
Posted 24 May 2011 - 11:58 AM
dargueta said:
A few things:
Your biggest mistake:
You read an integer from the console, put it in $t0, then immediately overwrite $t0 with 1.
Another thing - you forgot the terminating null for your first message:
These are just some things I noticed at a glance. Fix them, then we'll see what happens.
Your biggest mistake:
li $v0,5 syscall [B][COLOR="red"]move $t0,$v0[/COLOR][/B] [B][COLOR="red"]li $t0,1[/COLOR][/B] li $t1,2 li, $t2,10000
You read an integer from the console, put it in $t0, then immediately overwrite $t0 with 1.
Another thing - you forgot the terminating null for your first message:
.data msg: .asciiz "the sum of integers= \n" [B][COLOR="red"].byte 0[/COLOR][/B] count: .asciiz "the count of integers= \n \n" .byte 0
These are just some things I noticed at a glance. Fix them, then we'll see what happens.
I've corrected the error, but
The program does not work with me
I have this message appear

Something else I would like to ask
after each message we must put .byte 0 ??
#7
Posted 24 May 2011 - 12:56 PM
Question 1: I forgot to mention you need .globl main at the beginning of your program to tell SPIM that you want that function to be globally usable.
Question 2: Yes.
What's this program supposed to do?
Question 2: Yes.
What's this program supposed to do?
sudo rm -rf /
#8
Posted 29 May 2011 - 01:09 PM
show the output for the code above
#9
Posted 29 May 2011 - 03:31 PM
#10
Posted 09 June 2011 - 10:42 PM
Immm, No i didn't
i get the correct answer.
thanks alot >>:)
i get the correct answer.
thanks alot >>:)
#11
Posted 10 June 2011 - 08:52 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









