Jump to content

MIPS program

- - - - -

  • Please log in to reply
11 replies to this topic

#1
amani

amani

    Newbie

  • Members
  • Pip
  • 5 posts
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 ,

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
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.

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
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
amani

amani

    Newbie

  • Members
  • Pip
  • 5 posts
i tried to solve it but i think there's some mistake

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
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
A few things:

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
amani

amani

    Newbie

  • Members
  • Pip
  • 5 posts

dargueta said:

A few things:

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

Posted Image


Something else I would like to ask
after each message we must put .byte 0 ??

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
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?
sudo rm -rf /

#8
amani

amani

    Newbie

  • Members
  • Pip
  • 5 posts
show the output for the code above

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Did you add .globl main at the beginning like I told you to?
sudo rm -rf /

#10
amani

amani

    Newbie

  • Members
  • Pip
  • 5 posts
Immm, No i didn't

i get the correct answer.

thanks alot >>:)


#11
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,705 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
No problem.
sudo rm -rf /

#12
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
I'm glad I helped.
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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users