How to find the max and min values in a 10 element array mips

Tagged: , ,

This topic contains 1 reply, has 2 voices, and was last updated by  ChrisImgtec 2 years, 12 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #31849

    I am still very much a newbie once it comes to MIPS programming so bear with me. I am trying to write a function that goes through a 10 element array and returns the max and minimum values of the array. So far I have:

    .data

    X .word 31, 17, 92, 46, 172, 208, 13, 93, 65, 112
    N .word 10
    minValue .asciiz “Minimum Value: “
    maxValue .asciiz “nMaximum Value: “
    values .asciiz “nValues divisible by 4: “

    .text

    main:

    la $a0, X
    la $a1, N

    jal MaxMin

    MaxMin:
    lw $t0, 0($a0)

    swap:
    move $t0, $s0
    move $s0, $s1
    move $s0, $t0

    The MaxMin function is supposed to return the maximum and minimum values of the X array for me to print out. My plan is to go through the array and if an element is greater than or less than another element, they get swapped using the swap function. The problem is I have no idea how to go about doing this because I do not really know the syntax that you are supposed to use when dealing with arrays. If anyone could help I would appreciate it.

    #39070

    ChrisImgtec
    Moderator

    This is a link to a sorting example. You could just use it and return the first and last elements of the array.

    http://stackoverflow.com/questions/20528668/sorting-integers-in-mips

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.