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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:54:45+00:00 2026-05-17T22:54:45+00:00

I’m probably missing something really obvious here, but I’ve been going over this over

  • 0

I’m probably missing something really obvious here, but I’ve been going over this over and over and I’m decidedly stuck. In the code below, $8 is incremented only if $2 != $0. Now I double and triple checked and the beq instruction works (for example if I change lop to end2, it does go there).

However, for some reason, $8 is incremented regardless, even if the branch is executed.

lop:   beq $3, $0, end2
       and $2, $3, $4

       sll $3, $3, 1

       beq $2, $0, lop     

       addi $8, $8, 1

       j lop

I’ve got to admit I’m completely stumped.

  • 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-17T22:54:46+00:00Added an answer on May 17, 2026 at 10:54 pm

    (The and after the first beq will always be executed, too.)

    MIPS has explicit pipeline hazards; by the time the decision to branch (or not) is made, the following instruction has already progressed far enough through the instruction pipeline that it will be executed regardless. This is known as the “branch delay slot”.

    In some cases you can arrange code to take advantage of this; if you can’t (or don’t want to), you can just put a nop in the following instruction.

    Some assemblers will reorder code (or fill in the nop) for you – e.g. gas, the GNU assembler, does, unless you tell it not to with a .set noreorder directive. But you still need to be aware of it when disassembling anyway.

    If you’re writing code without automatic reordering by the assembler, I recommend annotating the delay slot with some extra indentation to make it stand out:

    lop:   beq $3, $0, end2
             nop
           and $2, $3, $4
    
           sll $3, $3, 1
    
           beq $2, $0, lop     
             nop
    
           addi $8, $8, 1
    
           j lop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.