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

  • SEARCH
  • Home
  • 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 8105299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:07:34+00:00 2026-06-06T00:07:34+00:00

for (i = 0; i < 64; i++) { A[i] = B[i] + C[i];

  • 0
for (i = 0; i < 64; i++) {
A[i] = B[i] + C[i];
}

The MIPS instructions for the above C code is:

add $t4, $zero, $zero   # I1 i is initialized to 0, $t4 = 0
Loop: 
add $t5, $t4, $t1       # I2 temp reg $t5 = address of b[i]
lw $t6, 0($t5)          # I3 temp reg $t6 = b[i]
add $t5, $t4, $t2       # I4 temp reg $t5 = address of c[i]
lw $t7, 0($t5)          # I5 temp reg $t7 = c[i]
add $t6, $t6, $t7       # I6 temp reg $t6 = b[i] + c[i]
add $t5, $t4, $t0       # I7 temp reg $t5 = address of a[i]
sw $t6, 0($t5)          # I8 a[i] = b[i] + c[i]
addi $t4, $t4, 4         # I9 i = i + 1
slti $t5, $t4, 256       # I10 $t5 = 1 if $t4 < 256, i.e. i < 64
bne $t5, $zero, Loop    # I11 go to Loop if $t4 < 256

For I8, could the sw instruction not be replaced with an addi instruction? i.e addi $t5, $t6, 0

Wouldn’t it achieve the same task of copying the address of $t6 into $t5? I would like to know the difference and when to use either of them. Same could be said about the lw instruction.

Also, maybe a related question, how does MIPS handle pointers?

edit: changed addi $t6, $t5, 0.

  • 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-06-06T00:07:36+00:00Added an answer on June 6, 2026 at 12:07 am

    For I8, could the sw instruction not be replaced with an addi instruction? i.e addi $t6, $t5, 0

    No. The sw instruction stores the result to memory. The add just manipulates registers. And lw gets a word from memory. It’s the only MIPS instruction that does so. (Other processors might and do have versions of add that access memory, but not MIPS.)

    It’s necessary to adjust your thinking when working in assembly language. Registers and memory are separate. In higher level languages, registers are (nearly) completely hidden. In assembly, registers are a separate resource that the programmer must manage. And they’re a scarce resource. A HLL compiler would do this for you, but by programming in assembly, you have taken the job for yourself.

    how does MIPS handle pointers?

    In MIPS, pointers are just integers (in registers or memory) that happen to be memory addresses. The only way they’re distinguished from data values is by your brain. The “pointer” is something invented by higher level language designers to relieve you the programmer of this burden. If you look closely, you’ll see that $t5 actually holds a pointer. It’s a memory address used by lw and sw as the address to load from or store to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running the following MIPS code in MARS simulator: add $t0, $zero, $zero
I have following asm MIPS code: 80031DB8 bnez $v0, loc_80031F58 80031DBC move $v0, $zero
Here is some MIPS assembly code I wrote to test the jump instruction: addi
I'm working with binary MIPS instructions and I found this helpful document . However,
I am studying a MIPS code that uses procedure but I can not understand
I'm writing a MIPS assembly code that will ask the user for the file
I am writing certain code in MIPS and I've come to the point where
Trying to convert this c code into MIPS and run it in SPIM. int
I am trying to translate a C program into MIPS assembly code In my
I have a simple c function that I need to convert to MIPS instructions

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.