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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:49:02+00:00 2026-06-01T03:49:02+00:00

Im trying to make a basic while loop example im preperation for my next

  • 0

Im trying to make a basic while loop example im preperation for my next assignment and im stuck in an infinite loop. $t3 never reaches to 3, or its not detecting that its at 3. What am i doing wrong here? Thanks!

.data           #data segment


msg1:.asciiz "please enter a number to convert to ASCI:  "
    nl:.asciiz "\n"
msg2:.asciiz "done!  "



.text           # Code segment
.globl main     # declare main to be global
main: 

    la $a0,msg1       # $a0 := address of message 1

    li $v0,4               # system call, type 4, print an string
    syscall

    li $t3,0 #initial value of $t3


    li $v0,5
    syscall #read an int

loop:

    la $a0,msg1       # $a0 := address of message 1

    li $v0,4               # system call, type 4, print an string
    syscall


    addi $t3,$t3,1  

    beq $3,$t3,Exit # branch to the label Exit if $t3=3

    j loop # branch unconditionally to loop ($t3 != 0)  

Exit:   
    li $v0,10       # System call, type 10, standard exit
    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-01T03:49:03+00:00Added an answer on June 1, 2026 at 3:49 am

    The problem is here:

    beq $3,$t3,Exit
    

    $3 is a register; it is not the value 3. It’s referring to the contents of the $3 register, which is actually $v1, which holds a value of 0 because you haven’t put anything in there. So instead of comparing to a value of 3, you’re comparing to 0. (It’s not actually an infinite loop, since $t3 will eventually wrap around to 0, but you get the idea.)

    MIPS lacks an instruction for comparing with an immediate, so you need to load the value 3 into a register first.

    Add this line before the loop, because you only need to load the value once:

    li $t4, 3
    

    And change your compare to this:

    beq $t4, $t3, Exit
    

    This will get you out of the loop. Your program will then print msg1 three times and exit, which I suspect isn’t what you want, but hopefully this lets you continue finishing up.

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

Sidebar

Related Questions

I've been trying to make this work for a while and it never seems
I've been trying to make my own basic .obj (Wavefront) renderer using the OpenGL
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
I'm trying to make a very basic php ORM as for a school project.
I am trying to make a basic webclient call to get an xml stream
Im trying to make a basic email system in Java. I have a server
I am trying to make a basic application which show my track on the
I am trying to make a basic Hex viewer out of a TMemo, I
I've been trying to make an app for a website for a while. I

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.