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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:52:51+00:00 2026-06-02T03:52:51+00:00

Question. Write MIPS assembley code which is equivalent to the following Java code fragment.

  • 0

Question. Write MIPS assembley code which is equivalent to the following Java code fragment.

    int x = 1 ;
    int y = 3 ;
    int c = 2 ;
    x = y - c ;
    if (x != y) { x = y + 5 ; }
    else { x = c ; } ;

This is what I have at the moment.

.data 
X: .word 1
Y: .word 3
C: .word 2
.text
main:
la $t1, X 
la $t2, Y
la $t3, C
lw $t1, ($t1)
lw $t2, ($t2)
lw $t3, ($t3)
sub $t1, $t2, $t3
li $v0, 1
beq $t1, $t2, iflabel
add $t1,$t3, 0 # sets x = c by adding zero to c and putting result in $t1 (register for x) used.
iflabel: add $t1,$t2,5
syscall
li $v0, 10

As Far as I can tell ‘8’ should be printed, but instead 0 is ?!?, not a homework question, just some revision question on MIPS. I can guess that my syscall ‘s are probably in the wrong places and possibly causing the error maybe?, I’m using MARS to program in, as I can see the contents of the register and run each line one by one, but still doesn’t help my problem.

  • 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-02T03:52:54+00:00Added an answer on June 2, 2026 at 3:52 am

    Your conditions are backwards: right now you have it so that is X is equal to Y it’ll add 5, but from the Java code it looks like you want it the other way around:

    bne $t1, $t2, iflabel
    

    Secondly, your +5 code flows into the other condition. You need a label after the if/else block, and you need to branch to it after handling the if-true code.

    Thirdly, you should be loading the $v0 vector immediately before doing syscall, and there’s no reason to be doing it afterward.

    Fourthly, syscall 1 needs the integer to be in $a0. You can directly add Y+5 or C+0 into $a0.

    Final code should be:

    .data 
    X: .word 1
    Y: .word 3
    C: .word 2
    
    .text
    main:
    la $t1, X 
    la $t2, Y
    la $t3, C
    lw $t1, ($t1)
    lw $t2, ($t2)
    lw $t3, ($t3)
    sub $t1, $t2, $t3
    bne $t1, $t2, iflabel
    add $a0,$t3, 0
    b endif
    iflabel: add $a0,$t2,5
    endif:
    li $v0, 1
    syscall
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have question how write program which calculates following procedures http://en.wikipedia.org/wiki/Tetration i have exponential
Following this question: Weird MIPS assembler behavior with jump (and link) instruction I have
Question simple and quick: I have started to use Netbeans to write some code
This is just a question on how to write my code for a COM
I'm stuck with this Java homework question: Write a new method, Refund, that simulates
My teacher gave me this question: Write a program that does the following: Enter
Question: write a Java program which accepts s list of existing text files from
i'm newbie in haskell, and i have question: i write code: word_list = [list,
I have this question: Write a program to display the sum of the series
I have a noobie question: I need to write SQL script that returns 3

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.