MIPS Assembly Language Programming - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

MIPS Assembly Language Programming

Description:

Prints the minimum and the maximum value. Problem 1 ... N, calls the function fib(N) and prints the value returned by the fib(N) function. ... – PowerPoint PPT presentation

Number of Views:169
Avg rating:3.0/5.0
Slides: 7
Provided by: cise8
Category:

less

Transcript and Presenter's Notes

Title: MIPS Assembly Language Programming


1
MIPS Assembly Language Programming
CDA 3101 Discussion Section 06
2
Problem 1
  • Write a function MinMax(X, N) to find the
    minimum and
  • maximum of an array X of N integers. The address
    of the
  • array is passed in a0, and the number of words
    in the array
  • is passed in a1. The minimum and maximum are
    returned in
  • registers v0 and v1 respectively.
  • Also, write a short main program that
  • Prompts the user for the value of N.
  • Dynamically allocates memory for storing array X
    of N integers. (Remember, 4 bytes per integer!)
  • Prompts user to enter N integers one by one to
    fill the array X.
  • Calls the MinMax function to find and return the
    minimum and maximum of the array X.
  • Prints the minimum and the maximum value.

3
Problem 1
  • Write a function MinMax(X, N) to find the
    minimum and
  • maximum of an array X of N integers. The address
    of the
  • array is passed in a0, and the number of words
    in the array
  • is passed in a1. The minimum and maximum are
    returned in
  • registers v0 and v1 respectively.
  • Also, write a short main program that
  • Prompts the user for the value of N.
  • Dynamically allocates memory for storing array X
    of N integers. (Remember, 4 bytes per integer!)
  • Prompts user to enter N integers one by one to
    fill the array X.
  • Calls the MinMax function to find and return the
    minimum and maximum of the array X.
  • Prints the minimum and the maximum value.

4
Problem 2
  • Implement a recursive function fib(n) to compute
    Fibonacci numbers. Also write a short main
    function that prompts the user to enter the
    integer N, calls the function fib(N) and prints
    the value returned by the fib(N) function.Note
    that
  • fib(0)0 fib(1)1
  • fib(n)fib(n-1) fib(n-2), ngt1.

5
Problem 2
  • Implement a recursive function fib(n) to compute
    Fibonacci numbers. Also write a short main
    function that prompts the user to enter the
    integer N, calls the function fib(N) and prints
    the value returned by the fib(N) function.
  • int fib(int N)
  • if(N 0) return 0
  • else if(N 1) return 1
  • else return fib(N-1) fib(N-2)

6
Key Points
  • Dynamically allocate memory
  • li v0, 9 Memory allocation service
  • li a0, ltintgt Allocate ltintgt bytes of
    mem.
  • syscall
  • move t0, v0 Move address of array to
    safety.
  • Recursion
  • self
  • addi sp, sp, -4 Allocate stack space
  • sw ra, 0(sp) Save old return
    address
  • jal self Jump to self
  • lw ra, 0(sp) Load old return address
  • addi sp, sp, 4 Restore stack to old state
Write a Comment
User Comments (0)
About PowerShow.com