#include #include "db_utils.h" #include "registers.h" int i, j; int n; int a[10]; int main() { /* Hello World */ char name[80]; DBPRINTF("\n\nBasic Starter Kit Lab (" __DATE__ ", " __TIME__")\n\n"); DBPRINTF("What is your name?\n"); i = 0; /* name not reinitialized between runs */ while (i++<=25) name[i] = '\0'; DBGETS(name,24); DBPRINTF("Hello, %s!\n", name); n = Initialize_Globals(); DBPRINTF("\nExpect three and four from Initialize_Globals:\n"); DBPRINTF("Value of i = %d and j = %d\n", i, j); DBPRINTF("\nInitalize_Globals returns five:\n"); DBPRINTF("Returned n = %d\n", n); DBPRINTF("\nReturn_7 should return seven:\n"); DBPRINTF("Return_7 VALUE = %d\n", Return_7()); /* ------------------------------------------------ */ Global_Array(); /* -------------------------------------------------- */ DBPRINTF("\nAn array of 10 values has been generated:\n"); i=-1; while (++i < 10) DBPRINTF("a[%d] = %d\n", i, a[i]); DBPRINTF("\nSum of array = %d\n", j); n = PassParameters(5, 10, 15, 20, 25); DBPRINTF("\nPassParameters returned: %d\n", n); n = Calculate(50.3, 100.0, 250); DBPRINTF("\nCalculate returned: %d\n", n); DBPUTS("\nProgram terminated. \n"); DBPUTS("Click HALT=F5 and then RESET=F6 to stop the microcontroller.\n"); return 0; } /* >>>>>>>>>>>>>>>End Main<<<<<<<<<<<<<<< */ int Initialize_Globals() /* Write-Only Parameters */ { asm(" ori %0, $0, 3 ; ori %1, $0, 4 “ : "=r" (i), "=r" (j) ); return 5; } int Return_7() /* Read-Only Parameters */ { asm("ori $v0, $0, %0" :: "n" (7)); } void Global_Array() /* Read and Write Parameters */ { asm(" .set noreorder ;\ addiu $sp, $sp, -12 ;\ sw $t0, 0($sp) ;\ sw $t1, 4($sp) ;\ sw $t2, 8($sp) ;\ ori $t0, $0, 0 ;\ or $t1, $0, %2 ;\ or $t2, $0, %1 ;\ add $t2, $t2, $t1 ;\ 1: addiu $t2, $t2, -4 ;\ sw $t1, 0($t2) ;\ add $t0, $t0, $t1 ;\ addiu $t1, $t1 ,-4 ;\ bnez $t1, 1b ;\ or %0, $0, $t0 ;\ lw $t2, 8($sp) ;\ lw $t1, 4($sp) ;\ lw $t0, 0($sp) ;\ addiu $sp, $sp, 12 ;\ .set reorder ;\ " \ : "=r" (j) \ : "r" (a), "n" (40) \ /* : "$8", "$9", "$10" */ /*defines fail!*/ \ ); } int PassParameters(int x, int y, int z, int s, int t) { asm("lw $v0,8($sp)"); /* returns x not t */ } int Calculate(double p, double q, int r) { asm("lw $v0,24($sp)"); /* returns r! */ }