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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:28:10+00:00 2026-06-11T10:28:10+00:00

I am learning MIPS programming, in which I am trying to implement If else

  • 0

I am learning MIPS programming, in which I am trying to implement If else conditions. But the problem is when I enter 2 to select subtract condition, the program doesn’t work. I know could have used BNE but I want to learn BEQ. Please tell me what is the problem is this code

.text

main:

li $t0,1
li $t1,2
li $t2,3
li $t3,4

li $v0,5
syscall

move $s0,$v0

beq $s0,$t0,ADDTN
ADDTN:


li $a0,40
li $v0,1
syscall

li $v0,5
syscall


move $s1,$v0

li $v0,5
syscall

move $s2,$v0

add $a0,$s1,$s2

li $v0,1
syscall

li $v0,10
syscall



beq $s0,$t1,SUBTN
SUBTN:

li $a0,50
li $v0,1
syscall

li $v0,5
syscall


move $s3,$v0

li $v0,5
syscall

move $s4,$v0

sub $a0,$s3,$s4

li $v0,1
syscall

li $v0,10
syscall
  • 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-11T10:28:12+00:00Added an answer on June 11, 2026 at 10:28 am

    for example:

    beq $s0,$t0,ADDTN
    ADDTN:
         # code for addition
         # ...
         # some syscalls
    beq $s0.$t1,SUBTN
    SUBTN:
     .
     .
     .
    

    I have no idea what the syscalls do (I usually don’t code for MIPS).

    But you check for a condition, i. e. equality of $s0 and one of $tn, and on equality you jump to the routine that suits the case. Very well, but the routine is immediately following the BEQ instruction, so the branch is absolutely superfluous here. And further, if the condition is not met, the program continues with the code directly following the BEQ instruction.

    The result is that the routines (add least ADDTN) are unconditionally executed. As said, I do not know what the syscalls do, but if addition works, I guess they are kinda jumps or so.

    Anyway, you must rearrange your code so that depending on the state of the tested condition another branch of your code is executed. This is a generic “template”:

            beq $s0, $t0, equal
            # this code is executed if $s0 and $t0 differ
             .
             .
            jmp notequal        # avoid also executing the code for equal
    equal:
            # code for the case $s0 and $t0 hold the same value
             .
             .
    notequal:
            # all that follows executes with no regard of the checked condition
    

    There are other techniques for branching several cases like yours (you seem to have to check four operations, I guess), but you should start understanding the basics first.

    [update: Well, actually it’s not that different, just that the code blocks are spread wider… /update]

    Have fun…

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

Sidebar

Related Questions

I'm learning MIPS Assembly by the book MIPS Assembly Language Programming , but my
I'm trying to learn MIPS Assembly by learning MIPS Assembly Language Programming . In
Learning C at University. This is not a homework, but I was trying to
Learning some VBA. So far, I've constructed this piece of code which should allow
Learning a lot in my few years of programming that the best projects are
Learning Ruby. Needed to create a hash of arrays. This works... but I don't
Learning CasperJS Trying to understand why the following is not displaying my results in
Learning spine.js I completed both the tutorials no problem, seems like a great framework,
Learning how to do a master page in asp.net. Trying to figure out how
Learning java server technologies, trying to clarify some things. There are few technologies that

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.