Jump to content

how to write this prog in MIPS(Mars)??

- - - - -

  • Please log in to reply
51 replies to this topic

#1
Ebda3

Ebda3

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
hi gents

i can't start to resolve this progarm it's so deficult ...

....Write program can be used to generate (n) random number (0<= x <1).
Show a sample output for 10 numbers????




:crying:

#2
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 help with homework, but we won't do it for you. What do you have so far? What libraries are you allowed to use, if any.
sudo rm -rf /

#3
Ebda3

Ebda3

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
I appreciate that...
But I do not know how to be like or what is steps to reach to the result....


I want more explanation. Because I very beginning in this program

Edited by Ebda3, 24 April 2011 - 11:41 AM.


#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,252 posts
  • Location:C:\Countries\US
So the question is "write a program that outputs a random number; the number must be greater than or equal to zero, but must be less than one."; is that right?

Maybe if you find some random number, you could divide that number by the [maximum number possible divided by 1].

There's this link I found about random numbers:
HowStuffWorks "How can a totally logical computer generate a random number?"

#5
Ebda3

Ebda3

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
here is a formula to generate random number but how i can write this prog in mips

Posted Image

i need more explain

#6
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
Split the formula up into distinct operations, like this:

Z = A * (B + C)

R0 := A

R1 := B

R1 += C

R0 *= R1

Z := R0


From there you should be able to translate it directly into machine language.

EDIT: Are you sure it's Xi + 1 and not X[i+1] like the G in the second line?
sudo rm -rf /

#7
Ebda3

Ebda3

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
R0 := A
R1 := B
R1 += C
R0 *= R1
Z := R0

:confused:
what do u mean about these??
R0:=A
B??
Z := R0

#8
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
Z = A * (B + C) consists of several operations, namely an addition, a multiplication, and a store. This is entirely conceptual, so I'm just making up register names R0, R1, etc. To translate this to MIPS assembly language...

We first load A, B, and C into registers:
R0 := A
R1 := B
R2 := C

Now we add B + C
R3 := R1 + R2

Multiply A by B + C
R4 := R0 * R3

Store the result into Z
Z := R4.

So our program now looks like:
Z = A * (B + C)

R0 := A

R1 := B

R2 := C

R3 := R1 + R2

R4 := R0 * R3

Z := R4


Translating this into equivalent instructions in MIPS:

lw      $t0, A

lw      $t1, B

lw      $t2, C

addu    $t3, $t1, $t2

mul     $t4, $t3, $t0

sw      $t4, Z


See how each line in my intermediate code corresponded exactly to one MIPS instruction? You need to do the same with your program. Write a high-level version of what you need to do (pseudocode works) and post it here.

Does this make sense? All you need to do is write the program in a high-level way that makes sense to you, then translate that into something like what I showed above, then from here to MIPS.
sudo rm -rf /

#9
Ebda3

Ebda3

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts

Quote

lw $t0, A
lw $t1, B
lw $t2, C
addu $t3, $t1, $t2
mul $t4, $t3, $t0
sw $t4, Z

is there wrong when i load A to $t0??

Posted Image

and aslo what about a seed in syscall(40) when i can use it
and random number(42) in syscall ??

:confused:

#10
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
My post was an example. I didn't do any part of your assignment for you. As for your second question, I'm not entirely sure what you mean by "when can I use it."
sudo rm -rf /

#11
Ebda3

Ebda3

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
Dear dargueta i never told u to do my assignment...

Quote

lw $t0, A
so the question is can the program store letter(A or B) in register as ur wrote ??

if ur answer is yes so how i can enter the values inside these letters ??
and y the program told there is a wrong ??

do u get why i'm so confused now ?

:confused: FYI i'm so beginner so I hope that u didn't angry from my stupid qeustion.
:)

Edited by dargueta, 02 May 2011 - 10:19 PM.
Fixed formatting


#12
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
You need to declare your variables first in the data section so you can reference them in your code:


# data and variables go in here

.data

    A:      .word   200

    B:      .word   15

    C:      .word   9

    Z:      .word   0

    

# code goes in here

.text

    lw      $t0, A

    lw      $t1, B

    lw      $t2, C

    addu    $t3, $t1, $t2

    mul     $t4, $t3, $t0

    sw      $t4, Z


    # SPIM exit

    li      $v0, 10

    syscall


sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users