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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:27:34+00:00 2026-06-12T12:27:34+00:00

I’m working on a homework assignment that requires me to compute the grayscale value

  • 0

I’m working on a homework assignment that requires me to compute the grayscale value of a series of hex values in an array. That’s the part I understand. I need to loop through this array of values until a -1 is encountered. Here’s what I’ve got:

 # --------------------------------
# Below is the expected output.
# 
# Converting pixels to grayscale:
# 0
# 1
# 2
# 34
# 5
# 67
# 89
# Finished.
# -- program is finished running --
#---------------------------------

.data 0x0
    startString:    .asciiz "Converting pixels to grayscale:\n"
    finishString:   .asciiz "Finished."
    newline:    .asciiz "\n"
    pixels:     .word   0x00010000, 0x010101,   0x6,        0x3333, 
                0x030c,     0x700853,   0x294999,   -1

.text 0x3000

main:
    ori $v0, $0, 4              #System call code 4 for printing a string
    ori $a0, $0, 0x0            #address of startString is in $a0
    syscall                 #print the string

LOOP:   ori $a0, $0, 0x0 
    lw $t1, 48($a0)
    beq $t1 -1, exit
    addi $t4, $0, 3
    sll $t2, $t1, 8
    srl $s1, $t2, 24    #$s1 becomes red value
    sll $t2, $t1, 16
    srl $s2, $t2, 24    #$s2 becomes green value
    sll $t2, $t1, 24
    srl $s3, $t2, 24    #$s3 become blue value
    add $t1, $s1, $s2
    add $t1, $t1, $s3
    div $t1, $t4
    mflo $s4        #$s4 becomes grayscale value
    or $a0, $0, $s4
    ori $v0, $0, 1
    syscall
    ori $v0, $0, 4
    ori $a0, $0, 43
    syscall
    j LOOP

exit:

    ori $v0, $0, 4              #System call code 4 for printing a string
    ori $a0, $0, 33             #address of finishString is in $a0; we computed this
                        #  simply by counting the number of chars in startString,
                        #  including the \n and the terminating \0

    syscall                 #print the string

    ori $v0, $0, 10             #System call code 10 for exit
    syscall                 #exit the program

I know that 48 needs to be incremented by 4 for every iteration of the loop, I just have no idea how to do this in MIPS. Any help is much appreciated!

  • 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-12T12:27:35+00:00Added an answer on June 12, 2026 at 12:27 pm

    What you should do is use some register to hold the value of the index of the array you are working with, and in each iteration increment that register with 4.

    It is also a bad idea to just put the constant where your array is located, because if you later change the location in memory of your array you have to update that constant too. Instead, use a label and let the assembler figure out the actual location.

    Suppose we use register $a1 to hold the index. Then, we just need to make some minor changes to your code:

        ori $a1, $0, 0x0   # Initialize index with 0
    LOOP:  
        lw $t1, pixels($a1)  # We use the label name instead of the actual constant
             ...
             ...
        addi $a1, $a1, 4   # Increment index by 4
        j LOOP
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have an array which has BIG numbers and small numbers in it. 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.