4
1 MIPS MIPS Assembly Language Assembly Language Programming Programming CDA 3101 Discussion Section 05 CDA 3101 Discussion Section 05

MIPS Assembly Language Programming

  • Upload
    barb

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

CDA 3101 Discussion Section 05. MIPS Assembly Language Programming. Problem1. 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 - PowerPoint PPT Presentation

Citation preview

Page 1: MIPS  Assembly Language  Programming

1

MIPS MIPS Assembly LanguageAssembly Language ProgrammingProgramming

CDA 3101 Discussion Section 05CDA 3101 Discussion Section 05

Page 2: MIPS  Assembly Language  Programming

2

Problem1Problem1Write 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 1. Prompts user to enter 10 integers one by one to fill a

global integer array X of size 102. Calls the MinMax function to find and return the

minimum and maximum of the array X.3. Prints the minimum and the maximum value.

Page 3: MIPS  Assembly Language  Programming

3

Problem2Problem2Implement the recursive function sillymultiply() given below in the MIPS assembly language. int sillymultiply(int x, int y) { int ret; if (y == 1) return x; ret = x + sillymultiply(x, y-1); return ret; }Also, write a short main function that prompts the user to enter the integers x and y calls the sillymultiply() function to compute x*y and prints the value returned by the sillymultiply(x,y) function.

Page 4: MIPS  Assembly Language  Programming

4

Some Key PointsSome Key Points• Read an integer from standard input

li $v0, 5 # Read_int system service

syscall # Read xmove $t0, $v0 # $t0 = $v0 = result of read = x