/* Notice: please no not **Include** any header file. You may use below functions to do all I/O syscall. Or you can define your on macro. */ void printInteger(int n) { __asm("li $v0,1"); __asm("syscall"); } void printFloat(float n) { __asm("li $v0,2"); __asm("syscall"); } void printDouble(double n) { __asm("mtc1 $a0,$f12"); __asm("mtc1 $a1,$f13"); __asm("li $v0,3"); __asm("syscall"); } void printString(const char* n) { __asm("li $v0,4"); __asm("syscall"); } int readInteger() { int n = 0; __asm("li $v0,5"); __asm("syscall"); __asm("sw $2,4($sp)"); return n; } float readFloat() { float n = 0; __asm("li $v0,6"); __asm("syscall"); __asm("mfc1 $v0,$f0"); __asm("sw $v0,4($sp)"); return n; } double readDouble() { _Alignas(16) double n; __asm("li $v0,7"); __asm("syscall"); __asm("mfc1 $v0,$f0"); __asm("mfc1 $v1,$f1"); __asm("sw $v0,0($sp)"); __asm("sw $v1,4($sp)"); return n; } void readString(char* p_string, int length) { __asm("li $v0,8"); __asm("syscall"); } void printChar(char n) { __asm("li $v0,11"); __asm("syscall"); } void printIntegerHex(int n) { __asm("li $v0,34"); __asm("syscall"); } void printIntegerBinary(int n) { __asm("li $v0,35"); __asm("syscall"); } int main() { float a = readFloat(); float b = readFloat(); if (b == 0) { if (a == 0) { char* err = (char*)"exception:divisor is 0.0 NaN\n"; printString(err); } else { char* err = (char*)"exception:divisor is 0.0 Infinity\n"; printString(err); } } else { float c = a / b; printFloat(c); } /* _Alignas(16) double d = readDouble(); long long index = 1; long long n = 1; _Alignas(16) double res = 1; _Alignas(16) double cur = 1; while (cur >= d) { n *= index; index ++; cur += n; res += cur; } printDouble(res);*/ }
Compile!