Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 1.03 KB

ch7_exercises.adoc

File metadata and controls

55 lines (44 loc) · 1.03 KB

Exercises

  1. Convert the exercises from chapter 5 to run with no pseudoinstructions (java -jar ~/rars_latest.jar np file.s on the command line).

  2. Convert the following C code to RISC-V using a jump table (Note in C/C++ enum values start at 0 and go up by one unless the user manually assigns a value, in which case it continues counting up from there).

    enum { STATE0, STATE1, STATE2, STATE3, STATE14 = 14, STATE42 = 42, STATE43, STATE44 };
    
    
    int main()
    {
    	int num;
    	do {
    		printf("Enter a number between 0 and 50: ");
    		scanf("%d", &num);
    	} while (num < 0 || num > 50);
    
    	switch (num) {
    	case STATE0:
    		puts("Zilch");
    		break;
    	case STATE1:
    		puts("Uno");
    		break;
    	case STATE2:
    		puts("Dos");
    		break;
    	case STATE3:
    		puts("Tres");
    		break;
    	case STATE14:
    		puts("Catorce");
    	case STATE42:
    		puts("The answer to life, the universe, and everything.");
    	case STATE43:
    		puts("Off by one");
    	case STATE44:
    		puts("4 * 11?");
    		break;
    	}
    
    	puts("Thanks for playing!");
    
    
    	return 0;
    }