MIPS Assembly Lang help - FirebirdV6.com/CamaroV6.com Message Board

Announcement

Collapse
No announcement yet.

MIPS Assembly Lang help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MIPS Assembly Lang help

    I need some help with MAL. My professor seems to think we can magically figure out assembler errors even though this is our very first MAL program. I've got the program itself down. It calculates the sum of 1, 3, and 7 using only subtraction.
    </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">#
    # *** Equivalences ***
    #
    print_int = 1

    #
    # *** Data ***
    #
    .data
    x: .word 1
    y: .word 3
    z: .word 7

    ###
    ### *** Instructions ***
    ###

    .text
    main: sub $s0, $0, x # subtract x from 0
    sub $s0, $s0, y # subtract y from that
    sub $s0, $s0, z # subtract z from that
    sub $s1, $0, $s0 # subtract answer from 0
    li $v0, print_int
    lw $a0, $s1
    syscall

    jr $ra</pre>[/QUOTE]I'm getting the following parse error when I try to load the file into the assembler
    </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">spim: (parser) parse error on line 28 of file onlysub.s
    sub $s0, $0, x # subtract x from 0
    ^</pre>[/QUOTE]I have no idea what its complaining about.
    ~Derrick <a href=\"http://www.appstate.edu/~do54457/\" target=\"_blank\"><i>My Webpage</i></a><br /><b>\'96 3.8L V6 M5 Firebird Y87</b> | <b>162.8 RWHP</b> / <b>196.7 RWTQ</b> <br /><b>•</b> SLP CAI <b>•</b> <a href=\"http://tech.firebirdv6.com/y87.html\" target=\"_blank\"><b>Y87</b> Package</a> - 3.23s <b>•</b> 180º thermo w/ fan switch <b>•</b> TB spacer from DEE<br />1991 Jeep Cherokee Laredo 4x4

  • #2
    It's complaining about the spim paser sub file! STOOPID! [img]tongue.gif[/img]

    Looks like Greek to me.
    <b><a href=\"http://members.cox.net/95batmobile/d86f.jpg\" target=\"_blank\">Sinister Six©</b></a><br /><a href=\"http://www.sounddomain.com/id/95batmobile\" target=\"_blank\">My \'95 Bird</a><br />I am not afraid of storms, for I am learning how to sail my ship.

    Comment


    • #3
      I'm not familiar with MIPS, but should "main:" be on a seperate line from the code perhaps?

      Also when you say "sub $s0, $0, x", I believe that's subtracting x from register 0, not the number 0. Doesn't look like you load anything into register 0 before that.

      Edit: n/m the $0. I guess $0 is a constant, while $1 and up are registers.
      Matt
      1998 Mystic Teal Camaro M5
      Whisper Lid, Pacesetter Headers, Catco Cat, Dynomax Super Turbo, B&M Shifter, BMR STB, LSD, P&P Intakes, GT2 Cam, Comp OE Lifters, 1.7 Roller Rockers, Pushrods, SSM Heads, DHP PowrTuner.

      Comment


      • #4
        Well, it's been about 10 years since I've touched assembly languages, but I'll take a guess and say that you cannot use a defined constant as an operand to an opcode. You've got:

        sub $s0, $0, x

        I would suggest trying:

        lw $t1, x
        sub $t0, $0, $t1

        ... and change the other sub opcode calls as well.

        Comment


        • #5
          Thanks guys. I finally caught up with my professor and he pointed out that I can't use variables in my operand specifiers, but you can use constants, like "X = 1"

          $0 is register 0, and is always a zero

          I also needed to "move" the answer into $a0, not load

          For those that care it looks like this now
          </font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> .text
          main: lw $s5, x # load x into $s5
          lw $s6, y # load y into $s6
          lw $s7, z # load z into $s7
          sub $s0, $0, $s5 # subtract x from 0
          sub $s0, $s0, $s6 # subtract y from that
          sub $s0, $s0, $s7 # subtract z from that
          sub $s1, $0, $s0 # subtract answer from 0
          li $v0, print_int
          move $a0, $s1
          syscall

          jr $ra # return to OS</pre>[/QUOTE]

          [ March 03, 2005, 05:01 PM: Message edited by: Dojo2000 ]
          ~Derrick <a href=\"http://www.appstate.edu/~do54457/\" target=\"_blank\"><i>My Webpage</i></a><br /><b>\'96 3.8L V6 M5 Firebird Y87</b> | <b>162.8 RWHP</b> / <b>196.7 RWTQ</b> <br /><b>•</b> SLP CAI <b>•</b> <a href=\"http://tech.firebirdv6.com/y87.html\" target=\"_blank\"><b>Y87</b> Package</a> - 3.23s <b>•</b> 180º thermo w/ fan switch <b>•</b> TB spacer from DEE<br />1991 Jeep Cherokee Laredo 4x4

          Comment


          • #6
            It makes sense. The variables would be treated as addresses in the data segment of the application, and the opcodes can only act on registers or constant values. The reason defined constants like your x, y and z work is because they are swapped out for the actual values in the code before it is compiled.

            Comment

            Latest Topics

            Collapse

            There are no results that meet this criteria.

            FORUM SPONSORS

            Collapse
            Working...
            X