#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

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


    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????
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,534
    Rep Power
    1906
    To answer your question - How to write this prog in MIPS(Mars)?):
    Start learning the assemble language.. everything is difficult at the beginning.

    Unless you read the sticky and have a more "direct"/precise question, the best we can do is redirect you to google and/or a assemble "manual".
    Like this one: http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm
    You can also take at look at http://en.wikibooks.org/wiki/MIPS_Assembly
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0
    here is my work but i can't find the problem
    the problem when i do run only
    but when i do assemple it shows me is sucssefully

    a: .word 673
    c: .word 37 x: .word 1
    .text
    lcm: ## argument: none, returns X(n+1) in $v0
    lw $t1, a # const a
    lw $t2, c # const c
    lw $t3, x # current X
    multu $t3, $t1 # HILO <- X * a
    mflo $v0 # v0 <- Lo
    addu $v0, $v0, $t2 # v0 += c
    sw $v0, x
    jr $ra
    # lcminit - sets initial X for LCM RNG
    # X = $a0, return#
    lcminit:sw, $a0, x # save $a0 in x
    jr $ra

    lcmmod:
    # $v0 = lcm() % $a0; return $v0

    addi $sp, $sp, -4 # push return address
    sw $ra, 0($sp) #
    jal lcm # v0 <- lcm (32 bit word)
    divu $v0, $a0
    mfhi $v0 # v0 <- lcm % a0
    lw $ra, 0($sp) # pop return address
    addi $sp, $sp, 4 #
    jr $ra



    # main program
    .text # main MUST BE GLOBAL
    .globl main
    main:
    loop: # PRINT prompt
    .data
    prompt: .asciiz "\nX(0)(-1 to exit): "
    .text
    la $a0, prompt
    li $v0, 4
    syscall
    li $v0, 5 # read i
    syscall
    sw $v0, -12($fp)
    move $a0, $v0
    jal lcminit #initialize thge LCM RNG
    blt $v0, 0, exit # If i<0, exit
    .data # PRINT ans
    ans: .asciiz "lcm is: "
    modulus:.word 1000
    .text
    la $a0, ans ###replaced
    li $v0, 4
    syscall
    li $s3, 3 # loop 3 times
    lcmloop:
    blt $s3, 1, prompt # if done loop, get new X(0)
    sub $s3, $s3, 1
    lw $a0, modulus
    # CALL lcmmod
    jal lcmmod
    # PRINT lccmod
    move $a0, $v0
    li $v0, 1
    syscall
    .data # print comma
    comma: .asciiz ","
    .text
    la $a0, comma
    li $v0, 4
    syscall
    b lcmloop # next lcm
    exit:
    li $v0, 10 # Appropriate way to end assembly code
    syscall
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,534
    Rep Power
    1906
    You have to be more descriptive.

    When/where (in code) does it start to fail?
    What did you expect?
    What actually happen?

IMN logo majestic logo threadwatch logo seochat tools logo