Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 647389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:43:01+00:00 2026-05-13T21:43:01+00:00

Trying to convert this c code into MIPS and run it in SPIM. int

  • 0

Trying to convert this c code into MIPS and run it in SPIM.

int A[100], B[100];
for(i=1; i<100; 1++){
A[i] = A[i-1] + B[i];
}

So far this is what I have.

    # comments are delimted by has marks

.data
A:   .word  0:100        # array of 12 integers
B:   .word  0:100        # array of 12 integers


.text
main:
    li $v0, 1       # load the value "1" into register $v0
    li $t0, 1       # load the value "1" into register $t0
    li $t1, 100     # load the value "100" into register $t1
    blt $t0, $t1, loop # branches to Loop if $t0 < 100
    la $t9, B
    la $t8, A

loop:
    sll $t0, $t0, 2
    add $t2, $t9, $t0 
    lw $s4, 0($t9)
    add $t3, $t0, -1
    add $t4, $t8, $t3
    lw $s5, 0($t4)
    add $t5, $t2, $s5
    add $t6, $s0, $t0
    sw $t7, 0($t5)
    addi $t0, $t0, 1
    li $v0, 1 # system call for print_int
    move $a0, $t0 # the sum to print
    syscall # print the sum

When running in SPIM I get the following errors:

Exception occurred at PC=0x00400040
  Bad address in data/stack read: 0x00000004
Exception occurred at PC=0x0040004c
  Unaligned address in inst/data fetch: 0x00000003
Exception occurred at PC=0x00400058
  Bad address in data/stack read: 0x00000000
Attempt to execute non-instruction at 0x0040006c

Some direction would be nice. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:43:01+00:00Added an answer on May 13, 2026 at 9:43 pm

    You are branching to loop (blt $t0, $t1, loop) before you initialize the pointers to A and B. You need to move the blt $t0, $t1, loop to the end of your code, not have it at the beginning.

    I hate to do this, but there are too many things wrong to list them all. Try this:

    .data 
    A:   .word  0:100        # array of 100 integers 
    B:   .word  0:100        # array of 100 integers 
    
    
    .text 
    main: 
        li $t0, 4       # load the value "1" into register $t0 
        li $t1, 400     # load the value "100" into register $t1 
        la $t9, B 
        la $t8, A 
    
    loop: 
        add $t2, $t9, $t0  # $t2 = B + i
        lw $s4, 0($t9)     # $s4 = B[i]
        add $t3, $t0, -4   # $t3 = i - 1
        add $t4, $t8, $t3  # $t4 = A + i - 1
        lw $s5, 0($t4)     # $s5 = A[i - 1]
        add $t5, $t8, $t0  # $t5 = A + i
        add $t6, $s4, $s5  # $t6 = B[i] + A[i - 1]
        sw $t6, 0($t5)     # A[i] = $t6
        addi $t0, $t0, 4   # i++
    
        li $v0, 1 # system call for print_int 
        move $a0, $t6 # the sum to print 
        syscall # print the sum
    
        blt $t0, $t1, loop # branches to Loop if $t0 < 100 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, see the Repositories API page. You do a post… May 16, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer You could make ajax calls back to CI for validation… May 16, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer Since it's not inside the <textarea> you need to traverse… May 16, 2026 at 6:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to convert this c# code into c++/cli code: class MyRange : IEnumerable<int>
I am trying to convert VB6 code to c# and I ran into this
How can I convert this piece of VB6 code into C#? http://pastebin.com/f16e19351 I've tried
I'm trying to convert a preexisting javascript function into a jQuery function. The function
I'm using process.Start to run Convert.exe. This program's purpose is to convert all files
I am trying to use the following code to convert a hash of options
I have a code-base that I'm looking to split up and add to by
Hello everyone I'm trying to convert a PKCS#8 private key that I generate in
I'm trying to convert spherical coordinates (namely latitude and longitude from a GPS device)
I'm trying to convert my LinearLayout to a bitmap so that I can save

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.