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 8774647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:37:16+00:00 2026-06-13T18:37:16+00:00

I have a question about several MIPS instruction in the code below 1. addi

  • 0

I have a question about several MIPS instruction in the code below
1. addi is an arithmetic instruction, what it’s purpose ?
2. why there is single nopafter j and beq, but there are multiple nops after addi ?
Thanks !

if(a==b)  x=3; /* simple C code */
else      x=4;
y=5;  

       lw   $1,a       # possible unoptimized assembly language
       lw   $2,b       # no ($0) shown on memory access
       nop             # wait for b to get into register 2
       nop             # wait for b to get into register 2
       beq  $1,$2,lab1
       nop             # branch slot, always executed *********
       addi $1,4       # else part
       nop             # wait for 4 to get into register 1
       nop             # wait for 4 to get into register 1
       sw   $1,x       # x=4;
       j    lab2
       nop             # branch slot, always executed *********    
lab1:  addi $1,3       # true part  
       nop             # wait for 3 to get into register 1
       nop             # wait for 3 to get into register 1
       sw   $1,x       # x=3;  
lab2:  addi $1,5       # after if-else, always execute
       nop             # wait for 5 to get into register 1
       nop             # wait for 5 to get into register 1
       sw   $1,y       # y=5;
  • 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-13T18:37:17+00:00Added an answer on June 13, 2026 at 6:37 pm

    addi is “add immediate” it adds an immediate value (a constant, an integer) to the contents of a register. the other add variant(s) are register adding with registers.

    The nops after addi and the descriptions make no sense at all from a mips perspective. Mips is well used for educational purposes and the particular implementation you are using or being taught might require time for the addi instruction to decode and execute and store the result to the register file before that register can be used as an input to another instruction. Normally the mips core (or any modern pipelined processor for that matter) will block the next instruction or use other solutions to short cut the result of one instruction that is the input to a following instruction.

    it is not only the addi but also the lw where you see these nops used to delay time as the comments say for the result to be stored in the register.

    At a minimum think of the basic steps, fetch, decode, execute, store results. this code seems to be allowing time for at least some of these steps to complete even though a real mips wouldnt need to.

    Having the delay slot after a branch is very much a mips thing (sure others do it to but it is more rare than common). The easy way to do it is to just put a nop after every branch or jump and waste the cycle. Eventually you will learn when you can take one of the instructions before the branch and put it after, otherwise using a nop if you cant find one.

    In general the code looks fine. for the addi instructions to work so that the code is a representative of the C code, the addi really needs to use register 0 which is always a zero. Addi takes a register and an immediate adds them together and puts the result in a different register, there are two registers for an addi and one constant…The code you have only shows one register. For all of the uses of addi in that code if you think of it this way:

    addi $1,4 
    changes to 
    addi $1,$0,4
    register $0 is always zero so this instruction really means
    $1 = 0 + 4 = 4
    $1 = 4
    

    I know the mips instructions from a formal perspective and from a machine code perspective, perhaps addi $1,4 is a shortcut that represents the more formal addi $1,$0,4. Assemble the code then examine the machine code for that instruction and you will probably see the two registers $1 and $0 with the immediate 4.

    Mips does not have a mov instruction where you can move a whole register sized immediate in one shot. The lui instruction is used to put bits in the upper half of a register and zeros in the lower half. Lui followed by an addi or an ori can be used as a team to load an immediate. Or if the upper bits are zeros then addi or ori with register 0 ($0) can be used to set the lower bits in a single instruction. For this asm to represent the C code the latter must be the case.

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

Sidebar

Related Questions

I have several question about MSISDNs. I understand: MSISDN is the basically the phone
I have tried looking though several of the already asked question about this topic
This other SO question asks about an autocomplete textbox in WPF. Several people have
There are several other questions about this topic that I have gone through, but
There have been several questions posted to SO about floating-point representation. For example, the
Quick question about CI. I have a view with a form, several text input
I have several question about integrating integrating Doctrine 2.2 & Zend framework. I know
Total beginner question about jQuery: I have a Form that contains several TextBoxes (input
I have a question about dependencies in CCNET. I have several projects, each of
I have a question about the exit button. I have read several posts on

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.