Question

In: Computer Science

In MIPS assembly language, write a function that will display the max and min value in...

In MIPS assembly language, write a function that will display the max and min value in an array. Then write a function to calculate and display the average of all values in an array. This must be done in MIPS assembly language.

Solutions

Expert Solution

MIPS Program:

$LC0:

        .ascii  "Maximum Element:%d\000"

$LC1:

        .ascii  "Minimum Element:%d\000"

display_max_and_min:

        addiu   $sp,$sp,-48

        sw      $31,44($sp)

        sw      $fp,40($sp)

        move    $fp,$sp

        sw      $4,48($fp)

        sw      $5,52($fp)

        li      $2,-2147483648                  # 0xffffffff80000000

        sw      $2,24($fp)

        li      $2,2147418112                 # 0x7fff0000

        ori     $2,$2,0xffff

        sw      $2,28($fp)

        sw      $0,32($fp)

        b       $L2

        nop

$L5:

        lw      $2,32($fp)

        nop

        sll     $2,$2,2

        lw      $3,48($fp)

        nop

        addu    $2,$3,$2

        lw      $3,0($2)

        lw      $2,24($fp)

        nop

        slt     $2,$3,$2

        beq     $2,$0,$L3

        nop

        lw      $2,32($fp)

        nop

        sll     $2,$2,2

        lw      $3,48($fp)

        nop

        addu    $2,$3,$2

        lw      $2,0($2)

        nop

        sw      $2,24($fp)

$L3:

        lw      $2,32($fp)

        nop

        sll     $2,$2,2

        lw      $3,48($fp)

        nop

        addu    $2,$3,$2

        lw      $3,0($2)

        lw      $2,28($fp)

        nop

        slt     $2,$2,$3

        beq     $2,$0,$L4

        nop

        lw      $2,32($fp)

        nop

        sll     $2,$2,2

        lw      $3,48($fp)

        nop

        addu    $2,$3,$2

        lw      $2,0($2)

        nop

        sw      $2,28($fp)

$L4:

        lw      $2,32($fp)

        nop

        addiu   $2,$2,1

        sw      $2,32($fp)

$L2:

        lw      $3,32($fp)

        lw      $2,52($fp)

        nop

        slt     $2,$3,$2

        bne     $2,$0,$L5

        nop

        lw      $5,28($fp)

        lui     $2,%hi($LC0)

        addiu   $4,$2,%lo($LC0)

        jal     printf

        nop

        lw      $5,24($fp)

        lui     $2,%hi($LC1)

        addiu   $4,$2,%lo($LC1)

        jal     printf

        nop

        nop

        move    $sp,$fp

        lw      $31,44($sp)

        lw      $fp,40($sp)

        addiu   $sp,$sp,48

        j       $31

        nop

$LC2:

        .ascii  "Average:%f\000"

display_Average:

        addiu   $sp,$sp,-48

        sw      $31,44($sp)

        sw      $fp,40($sp)

        move    $fp,$sp

        sw      $4,48($fp)

        sw      $5,52($fp)

        sw      $0,28($fp)

        sw      $0,24($fp)

        b       $L7

        nop

$L8:

        lw      $2,24($fp)

        nop

        sll     $2,$2,2

        lw      $3,48($fp)

        nop

        addu    $2,$3,$2

        lw      $2,0($2)

        lw      $3,28($fp)

        nop

        addu    $2,$3,$2

        sw      $2,28($fp)

        lw      $2,24($fp)

        nop

        addiu   $2,$2,1

        sw      $2,24($fp)

$L7:

        lw      $3,24($fp)

        lw      $2,52($fp)

        nop

        slt     $2,$3,$2

        bne     $2,$0,$L8

        nop

        lw      $3,28($fp)

        lw      $2,52($fp)

        nop

        bne     $2,$0,1f

        div     $0,$3,$2

        break   7

        mfhi    $2

        mflo    $2

        mtc1    $2,$f0

        nop

        cvt.s.w $f0,$f0

        swc1    $f0,32($fp)

        lwc1    $f0,32($fp)

        nop

        cvt.d.s $f0,$f0

        mfc1    $7,$f0

        mfc1    $6,$f1

        lui     $2,%hi($LC2)

        addiu   $4,$2,%lo($LC2)

        jal     printf

        nop

        nop

        move    $sp,$fp

        lw      $31,44($sp)

        lw      $fp,40($sp)

        addiu   $sp,$sp,48

        j       $31

        nop

Program Screenshot:

Hope you understand...

if you have any doubts comment below...

plss dont dislike.....


Related Solutions

This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Write a MIPS assembly language procedure that implements the Towers of Hanoi recursive function given the...
Write a MIPS assembly language procedure that implements the Towers of Hanoi recursive function given the following declaration: void towers(int n, char source, char dest, char spare); The function outputs a message describing each move. The source, destination, and spare poles are indicated with a character identifier of your choosing ('A', 'B', 'C' are common). Write a MIPS assembly language program that demonstrates the Towers of Hanoi procedure. Your program should ask the user for the number of disks. The...
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS Assembly language program to request a file name from the user, open the...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write out the contents to the console. This is what I have so far: .data    fileName:   .space 100    prompt1:   .asciiz "Enter the file name: "    prompt2:    .asciiz ""    prompt3:   .asciiz "\n"    buffer:    .space 4096 .text    main:        #        li $v0, 4        la $a0, prompt1       ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT