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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:39:09+00:00 2026-06-01T16:39:09+00:00

I have to program in Assembly (MIPS) a function to return the max value

  • 0

I have to program in Assembly (MIPS) a function to return the max value of an array.

The C code is this:

#include <stdio.h>
#include <stdlib.h>

int MaxAssembly(int *ptr, int num_elements); 

int main ( ) 
{ 
  int n=9; 
  int tab[] = {2, -8, 0, 25, 14, 2, 9, 15, -32}; 
  printf("The maximum is %d \n", MaxAssembly(tab,n)); 

MaxAssemblyis the function I have to program in Assembly.

I’m not in the part to find the max. My problem in in reading the functions arguments. I have made this code to do some tests.

    .data

    .text
    .globl  MaxAssembly

MaxAssembly:
    add $9,$5,$zero
    move    $2,$9
    jr  $ra

Doing this code I can see that I’m reading the second function argument as expected. It’s printed on the screen The maximum is 9
Changing the code to:

    .data

    .text
    .globl  MaxAssembly

MaxAssembly:
    move    $2,$4
    jr  $ra

I can see that it’s reading the first argument of the function as a memory address and it’s printed on the screen The maximum is 2143429780. So far is working as expected.

The problem is when I try to read the element stored at that memory address (the first element of the array). I’m getting one segmentation fault…
I’m doing this:

    .data

    .text
    .globl  MaxAssembly

MaxAssembly:
    lw      $16,0($4)
    move    $2,$16
    jr  $ra

What am I doing wrong? wasn’t lwsupposed to store at $16 the first item of the array? Using lbis the same

  • 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-01T16:39:11+00:00Added an answer on June 1, 2026 at 4:39 pm

    Yes, lw $s0, 0($a0) will read a full word from the address in $a0 to $s0. Unlike, lb, memory access via lw must use word-aligned addresses (i.e., two LSB are zero). I suspect that’s where the problem occur.

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

Sidebar

Related Questions

I am trying to translate a C program into MIPS assembly code In my
I have to write an assembly program that will find the minimum of array
I have this issue using assembly MIPS. From the keyboard I read an integer
I have seen a assembly program written from a book about assemble: assume cs:code
I have a program ( main.c ) that calls an external assembly function (
I have a Linux x86-32 GAS assembly program terminating like this: movl $1, %eax
I have a C# program that uses a class from another assembly, and this
I currently have an assembly program which is modeled after the hexdump system function
Here is my short assembly program: ; This code has been generated by the
I decided to teach myself assembly language. I have realized that my program will

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.