1. Introduction
ICO
Computer Organization (CCIT4026)
HKU SPACE Community College
(Lab 06)
Student ID:
Name:
Date:
In this lab, we are going to do revision on all technique we have learnt in MIPS programming.
2. Lab Work
#include
int list[10];
void main()
{
int function;
printf(“Selection the function? ¡°);
scanf(¡°%d¡±, &function) ;
for (int i=0; i<10; i++) {
printf("value %d? ¡°,i+1);
scanf(¡°%d¡±, list[i]) ;
}
if (function==1)
result = fun_1(10,list);
else if (function==2)
result = fun_2(10, list);
else
result =-1;
printf(¡°The result is %d\n¡°, result);
}
1/2
ICO
int fun_1(int num, int list[])
{
int i,sum;
sum=0;
for (i=1; i<=num-2; i++)
sum+=list[i];
return sum;
}
int fun_2(int num, int list[])
{
return fun_3(list[]);
}
int fun_3( int list[])
{
return list[A];
}
** The value of ¡°A¡± is the 7th digit of your student ID **
(1) Implement a MIPS program based on the above C program
(a) The program will ask the user to select either function 1 or function 2
(b) A set of 10 numbers will be input by the user from the keyboard
(c) For function 1, the sum of the first eight numbers will be calculated
(d) For function 2, one of the elements in the array will be obtained (based on your student ID)
(2) You must use Procedure Call based on the C program
(3) In this program, only $t0, $t1, $s0, $s1, $ra, $sp, $v0, $v1, $a0, $a1 can be used.
(Stack is needed to back-up the value)
(4) Save the file as lab6.asm
(5) Assembly the program by clicking Run -> Assemble (6) Run the program by clicking Run -> Go
2/2