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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:28:45+00:00 2026-05-29T07:28:45+00:00

My goal is to translate the C code below to MIPS assembly. I feel

  • 0

My goal is to translate the C code below to MIPS assembly. I feel like I am missing a crucial part in my code. Can someone explain what I am doing wrong and what I need to do to fix the problem please?

Here is the C code:

char str[] = "hello, class";
int len = 0;
char *ptr = str;
while (*ptr && *ptr != ’s’)
   ++ptr;
len = ptr - str;

Here is my code so far:

.data
    myStr: .asciiz "hello, class"
    s: .asciiz "s"
main:
    la $t0, myStr
    la $t1, s
    lbu $t1, 0($t1)

loop:
    beq $t0, $t1, continue
    addi $t0, $t0, 1
    j loop

continue:
    sub $v0, $t0, $t1
  • 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-29T07:28:46+00:00Added an answer on May 29, 2026 at 7:28 am

    Well, for a start, you’re not loading the byte from myStr inside the loop.

    Your lbu loads up the s character into $t1 before the loop starts but, inside the loop, you compare that with the address $t0.

    What you need to do is to lbu the byte from $t0 each time through the loop and compare that with $t1.

    I would think that this would be the fix though it’s been a while since I’ve done any MIPS.

    Change:

    loop:   beq    $t0, $t1, continue
            addi   $t0, $t0, 1
            j      loop
    

    into:

    loop:   lbu    $t2, 0($t0)            ; get character at current string location.
            beq    $t1, $t2, continue     ; exit loop is it matches.
            beq    $0, $t2, continue      ; exit loop if it's null.
            addi   $t0, $t0, 1            ; continue loop with next character.
            j      loop
    

    If your goal is to simply get C code converted to MIPS, you could just get a copy of a MIPS gcc compiler and run it through gcc -S and possibly at -O0 so you can understand the output 🙂

    That’s probably the fastest way. Of course, if your intent is to learn how to do it by hand, you may want to ignore this advice, although it would still be handy for learning in my opinion.

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

Sidebar

Related Questions

My goal is to have a user select a year and a month. Translate
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
My Goal I would like to have a main processing thread (non GUI), and
my goal is to write a stored proc that can collect all field values
My goal is to enhance inside scala code an existing Java class using a
I'm translating R code to c++ and I'd like to find an equivalent (optimal)
Goal: write a query that can bring back all the users of a company,
my goal i want to translate a left click to a right click my
I'm looking to translate words by letters/vowels. I'll try to explain. I have a
does anybody know we can translate from real image captured using cameras be converted

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.