Question

In: Electrical Engineering

Do Not Use Pseudo Insturctions or li la instructions, etc... Write and test a MIPS program...

Do Not Use Pseudo Insturctions or li la instructions, etc...

Write and test a MIPS program consisting of four functions. In the following descriptions, the symbol & means “address of”.

void main(): The main function must 1) print your name 2) call the readData function 3) call count function 4) complete the program. The main function must set up all parameters before calling each of the functions.

int readData (&array): The starting address of an array is passed to the function as a parameter using $a0. The function must prompt for and read and store integers in the array until either a zero is entered or 10 numbers are read. Once the tenth integer is entered, your program must stop reading. The function must return (using $v0) the number of values read and stored in the array (10 or less). The zero input is not part of the array and must not be stored in the array. If the first input is a zero, then the array will be empty and the count returned is zero.

float average (&array, count): The starting address of an array (in $a0) and the number of integers stored in the array (in $a1) are passed to the function. The purpose of the function is to calculate and return (using $f0) the floating point average of the numbers. To find the average, sum all the integers together and then divide by the count as a floating point value. If the count is zero, return 0.0. Use appropriate registers for the parameters and the return value.

void count (&array, count): The starting address of an array (in $a0) and the number of integers stored in the array (in $a1) are passed to the function. The function determines how many of the integers in the array are greater than or equal to the average. First the parameters for the average function are set and then average function is called to determine the average value. The returned value is then printed. Then each value in the array is tested to determine if its value is greater than or equal to the average. The count of the values greater than or equal to the average is then printed.

Example input and output:

Linda Chatting
Enter a number 3
Enter a number 6
Enter a number 2
Enter a number 4
Enter a number 0
The average is 3.750000000
There are 2 numbers greater than or equal to the average.

In addition,

 Functions must be called using jal and return using jr.

 Parameters must be passed as specified and used correctly. The readData, average and count

functions must access the array through the parameter, not directly.

 Be sure to comment all instructions. All functions must include comments describing the

function and its parameters and return value (if any). Be sure that your name and class ID appear at the beginning.

Solutions

Expert Solution

.comm   arr,40,4

        .comm   i,4,4
        .rdata
        .align  2
$LC0:
        .ascii  "%d\000"
        .text
        .align  2
        .globl  read
        .set    nomips16
        .set    nomicromips
        .ent    read
        .type   read, @function
read:
        .frame  $fp,32,$31              # vars= 0, regs= 2/0, args= 16, gp= 8
        .mask   0xc0000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    nomacro
        addiu   $sp,$sp,-32
        sw      $31,28($sp)
        sw      $fp,24($sp)
        move    $fp,$sp
        .cprestore      16
        movz    $31,$31,$0
        sw      $4,32($fp)
        lw      $2,%got(i)($28)
        nop
        sw      $0,0($2)
        b       $L2
        nop

$L4:
        lw      $2,%got(i)($28)
        nop
        lw      $2,0($2)
        nop
        addiu   $3,$2,1
        lw      $2,%got(i)($28)
        nop
        sw      $3,0($2)
$L2:
        lw      $2,%got(i)($28)
        nop
        lw      $2,0($2)
        nop
        sll     $2,$2,2
        lw      $3,32($fp)
        nop
        addu    $2,$3,$2
        move    $5,$2
        lw      $2,%got($LC0)($28)
        nop
        addiu   $4,$2,%lo($LC0)
        lw      $2,%call16(__isoc99_scanf)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,__isoc99_scanf
1:      jalr    $25
        nop

        lw      $28,16($fp)
        beq     $2,$0,$L3
        nop

        lw      $2,%got(i)($28)
        nop
        lw      $2,0($2)
        nop
        sll     $2,$2,2
        lw      $3,32($fp)
        nop
        addu    $2,$3,$2
        lw      $2,0($2)
        nop
        bne     $2,$0,$L4
        nop

$L3:
        lw      $2,%got(i)($28)
        nop
        lw      $2,0($2)
        move    $sp,$fp
        lw      $31,28($sp)
        lw      $fp,24($sp)
        addiu   $sp,$sp,32
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    read
        .size   read, .-read
        .align  2
        .globl  count
        .set    nomips16
        .set    nomicromips
        .ent    count
        .type   count, @function
count:
        .frame  $fp,8,$31               # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x40000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    nomacro
        addiu   $sp,$sp,-8
        sw      $fp,4($sp)
        move    $fp,$sp
        lw      $2,%got(i)($28)
        nop
        movz    $31,$31,$0
        lw      $2,0($2)
        move    $sp,$fp
        lw      $fp,4($sp)
        addiu   $sp,$sp,8
        j       $31
        nop

#       .set    macro
        .set    reorder
        .end    count
        .size   count, .-count
        .rdata
        .align  2
$LC1:
        .ascii  "Rahul Panda\000"
        .text
        .align  2
        .globl  main
#       .set    nomips16
#       .set    nomicromips
#       .ent    main
#       .type   main, @function
main:
        .frame  $fp,32,$31              # vars= 0, regs= 2/0, args= 16, gp= 8
        .mask   0xc0000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    nomacro
        addiu   $sp,$sp,-32
        sw      $31,28($sp)
        sw      $fp,24($sp)
        move    $fp,$sp
        .cprestore      16
        movz    $31,$31,$0
        lw      $2,%got($LC1)($28)
        nop
        addiu   $4,$2,%lo($LC1)
        lw      $2,%call16(printf)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,printf
1:      jalr    $25
        nop

        lw      $28,16($fp)
        nop
        lw      $4,%got(arr)($28)
        lw      $2,%got(read)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,read
1:      jalr    $25
        nop

        lw      $28,16($fp)
        nop
        lw      $2,%got(count)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,count
1:      jalr    $25
        nop

        lw      $28,16($fp)
        move    $5,$2
        lw      $2,%got($LC0)($28)
        nop
        addiu   $4,$2,%lo($LC0)
        lw      $2,%call16(printf)($28)
        nop
        move    $25,$2
        .reloc  1f,R_MIPS_JALR,printf
1:      jalr    $25
        nop

        lw      $28,16($fp)
        nop
        move    $sp,$fp
        lw      $31,28($sp)
        lw      $fp,24($sp)
        addiu   $sp,$sp,32
        j       $31
        nop

Related Solutions

PART 1: Design a program (using only native MIPS instructions, no pseudo instructions) that will prompt...
PART 1: Design a program (using only native MIPS instructions, no pseudo instructions) that will prompt user to enter three decimal numbers. Each decimal number will not exceed six digits The program can't ask user how many digits will be entered. Both numbers must be stored in memory as NULL terminated strings. The first number must be stored at the memory address 0x10000000. The second number must be stored in the memory 0x10000008. The third number must be stored at...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
MIPS assembly language. Why do "la label" instructions always need to be translated into 2 lines...
MIPS assembly language. Why do "la label" instructions always need to be translated into 2 lines of pseudo code? What about "lw label" instructions? Explain the similarities and differences in how they are implemented in MARS.
For this assignment, you are required to write a MIPS program that reads its own instructions...
For this assignment, you are required to write a MIPS program that reads its own instructions and counts the number of occurrences of each type of instruction (R-type, I-type, or J-type). To accomplish this task, your program should execute the following steps: First, your program should load the address of its first instruction (0x400000) into a register, and initialize three separate instruction class counters to zero. Next, your program should enter a loop that reads each instruction from memory. For...
I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that...
I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that meets the following requirements (NOTE: your program statements should follow the order of the requirements and each requirement should correspond to only one assembly instruction): Loads the hexadecimal equivalent of 23710 into register 13 using an immediate bitwise OR instruction Loads the hexadecimal equivalent of 183410 into register 17 using an immediate bitwise OR instruction Performs the bitwise AND operation on the operands stored...
How do I write a program in MIPS that will change all the characters in a...
How do I write a program in MIPS that will change all the characters in a string into lowercase. For instance: string: " CANBERRA AUSTRALIA" Output: "canberra australia"
Instructions Write a Java program that asks the user t enter five test scores. The program...
Instructions Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: * calcAverage -- This method should accept five test scores as arguments and return the average of the scores. * determineGrade -- This method should accept a test score as an argument and return a letter grade for the score, based on the following...
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...
Lab-3C   Pre-test Loop Write a MIPS program to count the number of students who failed in...
Lab-3C   Pre-test Loop Write a MIPS program to count the number of students who failed in a course. The final grades are given in an array. The fail grade is 60. Example: Array and Output      .data NoOfStudents: 10 Values:   60 70 80 50 90 80 55 90 80 70 Output: 2 students failed      .data NoOfStudents: 12 Values:   60 70 80 50 90 80 55 90 80 70 55 80 Output: 3 students failed
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS)...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS) which works as a simple calculator. The program will get two integer numbers, and based on the requested operation, the result should be shown to the user. a. The program should print a meaningful phrase for each input, and the result. i. “Enter the first number” ii. “Enter the second number” iii. “Enter the operation type” iv. “The result is” b. The user should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT