forked from leduythuccs/nachos-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added program ascii, bubblesort, and help
bubblesort.c check integer input Reformat ASCII print from 32 to 126, bubblesort.c assume 0 when enter illegal values, random.c print out the random number, modified tests Fix help.c 0<=n<=100
- Loading branch information
1 parent
d8bd212
commit 0072ce5
Showing
6 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "syscall.h" | ||
|
||
int main() { | ||
int i; | ||
for (i = 32; i <= 126; i++) { | ||
PrintNum(i); | ||
PrintChar(' '); | ||
PrintChar((char)i); | ||
PrintChar('\n'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "syscall.h" | ||
#define SIZE (100) | ||
|
||
int main() { | ||
int n, a[SIZE + 1], order, temp, i, j; | ||
do { | ||
PrintString("Enter n (0 <= n <= 100): "); | ||
n = ReadNum(); | ||
if (n < 0 || n > 100) | ||
PrintString( | ||
"n has to be an integer between 1 and 100 (inclusive), please " | ||
"try again\n"); | ||
} while (n < 0 || n > 100); | ||
|
||
for (i = 0; i < n; i++) { | ||
PrintString("Enter a["); | ||
PrintNum(i); | ||
PrintString("]: "); | ||
a[i] = ReadNum(); | ||
} | ||
|
||
do { | ||
PrintString("Enter sort order (1: increasing, 2: decreasing): "); | ||
order = ReadNum(); | ||
if (order != 1 && order != 2) | ||
PrintString("Wrong input, please try again\n"); | ||
} while (order != 1 && order != 2); | ||
|
||
for (i = 0; i < n; i++) { | ||
for (j = 0; j < n - 1; j++) { | ||
if (order == 1) { | ||
if (a[j] > a[j + 1]) { | ||
temp = a[j]; | ||
a[j] = a[j + 1]; | ||
a[j + 1] = temp; | ||
} | ||
} else if (order == 2) { | ||
if (a[j] < a[j + 1]) { | ||
temp = a[j]; | ||
a[j] = a[j + 1]; | ||
a[j + 1] = temp; | ||
} | ||
} | ||
} | ||
} | ||
|
||
PrintString("Sorted array: "); | ||
for (i = 0; i < n; i++) { | ||
PrintNum(a[i]); | ||
PrintChar(' '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "syscall.h" | ||
|
||
int main() { | ||
PrintString("Our team:\n"); | ||
PrintString("19120037 Le Duy Thuc\n"); | ||
PrintString("19120395 Tran Duy Tien\n"); | ||
PrintString("19120219 Ha Chi Hao\n\n"); | ||
PrintString( | ||
"ASCII: at directory code, run build.linux/nachos -x test/ascii to " | ||
"print the ASCII table\n"); | ||
PrintString( | ||
"Sort: at directory code, run build.linux/nachos -x test/bubblesort to " | ||
"start the sort program\n"); | ||
PrintString("\t- Enter n (the length of the array, 0 <= n <= 100)\n"); | ||
PrintString("\t- Enter n elements of the array\n"); | ||
PrintString( | ||
"\t- Enter the order you want to sort the array with (1: increasing, " | ||
"2: decreasing)\n"); | ||
PrintString( | ||
"\t- The program will print out the sorted array and then exit\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
int main() { | ||
int result; | ||
result = RandomNum(); | ||
PrintNum(result); | ||
} |