diff --git a/ps1/README.md b/ps1/README.md new file mode 100644 index 0000000..196b784 --- /dev/null +++ b/ps1/README.md @@ -0,0 +1,78 @@ +# Problem Set 1 - ECE391 spring 2024 + +### Logistics +Problem Set 1 is due **Tuesday 1/30 at 05:59:59 PM** in the master branch. Only one +person per group should have a `partners.txt` with **all** the netids of your partners on separate lines. +For this PS, form a group of **at least four students**. There is no cap on the maximum number of collaborators in the same group. +An example `partners.txt` would look like this if `elihf2` was submitting the group's solution. + +elihf2
+linghao3
+yuey10
+zhongbo2
+yuezel2
+dcaglar2
+ + +Note that if your netid is part of more than one `partners.txt`, you will recieve a 0 for the problem set. + +**You can attempt this problem set on the Class VM (devel) or on any EWS Linux computer.** + +### Problem 1: GNU Debugger (GDB) (5 pt) +Please write the command(s) you should use to achieve the following tasks in GDB. +1. Show the value of variable "test" in hex format. +2. Show the top four bytes on your stack word-by-word, e.g. it should look something like this "0x0102 0x0304", NOT "0x01020304". +3. Check all register values. +4. Set a breakpoint at "ece.c" line 391. +5. Connect to the test\_(no)debug vm in the lab setup. + +Please write your solution in p1\_soln.txt with answers to each question on a separate line. For example, your p1\_soln.txt should be of the form +> answer 1 +> +> answer 2 +> +> ... +> +> answer 5 + +### Problem 2: C to Assembly Translation (10 pt) +Write x86 assembly code for the body of the `binarysearch` function found in `binarysearch.c`. Make sure to set up and tear down the stack frame as well as save and restore any callee/caller-saved registers yourself (if you use them). Assume caller-saved registers are saved prior to the `binarysearch_asm` function being called for the first time. Include comments (but don't overdo it!) in your assembly code to show the correspondence between the C code and your x86 code. + +Also note that: +1. The `binarysearch_asm` function in `binarysearch_asm.S` is partially filled out for you, your job is to complete the function. +2. Please make sure your code and comments are easy to read. We reserve the right to take points off if your answer is too hard to follow. +3. You must synthesize your answer without the help of a computer. For example, you may not write the C code and then use the compiler to disassemble it. If you are caught doing this, you will receive a 0. +4. You must **translate** your code, a functionally equivalent algorithm with a different structure will recieve a 0. +5. You must write your solution in `p2/binarysearch_asm.S` and submit it through gitlab. + +To build the code (no debug flag): +`$ make clean && make` + +To run the code: +`$ ./binarysearch ./input_small.txt` + +To build the code (debug flag): +`$ make clean && make debug` + +To run the code (debug): +`$ gdb --args ./binarysearch ./input_small.txt` + +### Problem 3: Assembly to C Translation (10 pt) +Write a C function equivalent to the x86 assembly function, `mystery_asm` found in `mystery_asm.S`. + +1. Please make sure your code and comments are easy to read. We reserve the right to take points off if your answer is too hard to follow. +2. You must **translate** your code, a functionally equivalent algorithm with a different structure will recieve a 0. +3. You must write your solution in `p3/mystery.c` and submit it through gitlab. + +To build the code (no debug flag): +`$ make clean && make` + +To run the code: +`$ ./mystery ./input_1.txt` + +To build the code (debug flag): +`$ make clean && make debug` + +To run the code (debug): +`$ gdb --args ./mystery ./input_1.txt` + diff --git a/ps1/p1/grade.txt b/ps1/p1/grade.txt new file mode 100644 index 0000000..96828e9 --- /dev/null +++ b/ps1/p1/grade.txt @@ -0,0 +1 @@ +5/5 diff --git a/ps1/p1/p1_soln.txt b/ps1/p1/p1_soln.txt new file mode 100644 index 0000000..11e0a75 --- /dev/null +++ b/ps1/p1/p1_soln.txt @@ -0,0 +1,5 @@ +print/x test +x/2xh $esp +info registers +break ece.c:391 +target remote 10.0.2.2:1234 diff --git a/ps1/p2/Makefile b/ps1/p2/Makefile new file mode 100644 index 0000000..acc3595 --- /dev/null +++ b/ps1/p2/Makefile @@ -0,0 +1,31 @@ +# Makefile C to ASM +# Andrew Smith +# 1/24/20 + + +PROG := binarysearch + +CFLAGS += -m32 -Wall -std=c99 + +.PHONY: clean + +all: CFLAGS += -O0 +all: $(PROG) + +debug: CFLAGS += -O0 -g +debug: $(PROG) + +$(PROG): binarysearch_asm.o binarysearch.o main.o + $(CC) -m32 $^ -o $@ + +binarysearch_asm.o: binarysearch_asm.S + $(CC) $(CFLAGS) -c $< -o $@ + +binarysearch.o: binarysearch.c + $(CC) $(CFLAGS) -c $< -o $@ + +main.o: main.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f *.o $(PROG) diff --git a/ps1/p2/binarysearch.c b/ps1/p2/binarysearch.c new file mode 100644 index 0000000..86a0900 --- /dev/null +++ b/ps1/p2/binarysearch.c @@ -0,0 +1,55 @@ +/* + * tab:2 + * + * search.c - Implementation of C Recursive Depth First Search + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF ILLINOIS BE LIABLE TO + * ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, + * EVEN IF THE AUTHOR AND/OR THE UNIVERSITY OF ILLINOIS HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR AND THE UNIVERSITY OF ILLINOIS SPECIFICALLY DISCLAIM ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND NEITHER THE AUTHOR NOR + * THE UNIVERSITY OF ILLINOIS HAS ANY OBLIGATION TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Author: Aamir Hasan + * Version: 1 + * Creation Date: Fri Aug 30 2020 + * Filename: search.c + * History: + * AS 1 Fri Aug 30 2020 + * First written. + */ + +#include "binarysearch.h" + + +int32_t binarySearch(int32_t* arr, int32_t md, int32_t low, int32_t high) +{ + int mid = 0; + if (low <= high) + { + mid = (low + high) / 2; + if (md == arr[mid]) + { + return 1; + } + else if (md < arr[mid]) + { + return binarySearch(arr, md, low, mid - 1); + } + else + return binarySearch(arr, md, mid + 1, high); + } + else + return -1; +} diff --git a/ps1/p2/binarysearch.h b/ps1/p2/binarysearch.h new file mode 100644 index 0000000..d43685d --- /dev/null +++ b/ps1/p2/binarysearch.h @@ -0,0 +1,49 @@ +/* + * tab:2 + * + * search.h - Search function & helper function declarations + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF ILLINOIS BE LIABLE TO + * ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, + * EVEN IF THE AUTHOR AND/OR THE UNIVERSITY OF ILLINOIS HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR AND THE UNIVERSITY OF ILLINOIS SPECIFICALLY DISCLAIM ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND NEITHER THE AUTHOR NOR + * THE UNIVERSITY OF ILLINOIS HAS ANY OBLIGATION TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Author: Aamir Hasan + * Version: 1 + * Creation Date: Fri Aug 30 2020 + * Filename: search.c + * History: + * AS 1 Fri Aug 30 2020 + * First written. + */ + +#ifndef BINARYSEARCH_H +#define BINARYSEARCH_H + +#include +#include +#include + +// binarySearch +// searches for an element in the BST recursively +// Returns: +// 1 - found element +// -1 - element not found +extern int32_t binarySearch(int32_t* arr, int32_t md, int32_t low, int32_t high); + +extern int32_t binarySearch_asm(int32_t* arr, int32_t md, int32_t low, int32_t high); + +#endif \ No newline at end of file diff --git a/ps1/p2/binarysearch_asm.S b/ps1/p2/binarysearch_asm.S new file mode 100644 index 0000000..bc15346 --- /dev/null +++ b/ps1/p2/binarysearch_asm.S @@ -0,0 +1,116 @@ +/* + * tab:2 + * + * search_asm.S - Implementation of Assembly Recursive DFS + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF ILLINOIS BE LIABLE TO + * ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, + * EVEN IF THE AUTHOR AND/OR THE UNIVERSITY OF ILLINOIS HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR AND THE UNIVERSITY OF ILLINOIS SPECIFICALLY DISCLAIM ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND NEITHER THE AUTHOR NOR + * THE UNIVERSITY OF ILLINOIS HAS ANY OBLIGATION TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Author: Aamir Hasan + * Version: 1 + * Creation Date: Fri Aug 30 2020 + * Filename: search_asm.S + * History: + * AS 1 Fri Aug 30 2020 + * First written. + */ + +.global binarySearch_asm + +# Search ASM (Assembly) +# Searches for an element in a BST +# Declaration is in search.h +# +# Registers: +# eax - Return Value +# +binarySearch_asm: + pushl %ebp + movl %esp, %ebp + + #--- YOUR CODE HERE --- + subl $4, %esp # reserve 4 bytes on stack for 1 local vars called mid + pushl %edi + pushl %esi + pushl %ecx + pushl %ebx + + movl 8(%ebp), %ebx # load arr into EBX + movl 12(%ebp), %ecx # load md into ECX + movl 16(%ebp), %esi # load low into ESI + movl 20(%ebp), %edi # load high into EDI + + cmpl %edi, %esi # load low - high into flag + ja not_exist # if low > high return -1 + + movl $0, %eax # set eax to 0 + addl %esi,%eax + addl %edi, %eax # low + high -> eax + shrl %eax # eax = (low+high)/2 + + cmpl %ecx,(%ebx,%eax,4) # arr[mid] - md + je found + ja mid_larger_than_md + movl %eax, %esi # mid -> esi + incl %esi # new lower bound is mid+1 + + pushl %edi + pushl %esi + pushl %ecx + pushl %ebx + call binarySearch_asm + popl %ebx + popl %ecx + popl %esi + popl %edi + + + +mid_larger_than_md: + movl %eax, %edi + decl %edi + + pushl %edi + pushl %esi + pushl %ecx + pushl %ebx + call binarySearch_asm + popl %ebx + popl %ecx + popl %esi + popl %edi + +found: + movl $1, %eax + jmp finish_search + + +not_exist: + movl $-1, %eax + +finish_search: + popl %ebx + popl %ecx + popl %esi + popl %edi + addl $4, %esp + + #---------------------- + + leave + ret diff --git a/ps1/p2/grade.txt b/ps1/p2/grade.txt new file mode 100644 index 0000000..c11fa58 --- /dev/null +++ b/ps1/p2/grade.txt @@ -0,0 +1 @@ +10/10 \ No newline at end of file diff --git a/ps1/p2/input_large.txt b/ps1/p2/input_large.txt new file mode 100644 index 0000000..1cc1d3f --- /dev/null +++ b/ps1/p2/input_large.txt @@ -0,0 +1,16 @@ +15 1 +13 +3 +4 +12 +14 +10 +5 +1 +8 +2 +7 +9 +11 +6 +18 diff --git a/ps1/p2/input_small.txt b/ps1/p2/input_small.txt new file mode 100644 index 0000000..0c6fb9a --- /dev/null +++ b/ps1/p2/input_small.txt @@ -0,0 +1,8 @@ +7 20 +50 +30 +20 +40 +70 +60 +80 diff --git a/ps1/p2/main.c b/ps1/p2/main.c new file mode 100644 index 0000000..be0eecf --- /dev/null +++ b/ps1/p2/main.c @@ -0,0 +1,132 @@ +/* + * tab:2 + * + * main.c - I/O and BST problem setup + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF ILLINOIS BE LIABLE TO + * ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, + * EVEN IF THE AUTHOR AND/OR THE UNIVERSITY OF ILLINOIS HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR AND THE UNIVERSITY OF ILLINOIS SPECIFICALLY DISCLAIM ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND NEITHER THE AUTHOR NOR + * THE UNIVERSITY OF ILLINOIS HAS ANY OBLIGATION TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Author: Aamir Hasan + * Version: 1 + * Creation Date: Fri Aug 30 2020 + * Filename: main.c + * History: + * AS 1 Fri Aug 30 2020 + * First written. + */ + +#include +#include +#include +#include +#include + +#include "binarysearch.h" + +int32_t* import_arr(char* fname, uint32_t* find, uint32_t* num) { + FILE* f = fopen(fname, "r"); + uint32_t i, key, num_elements; + + + fscanf(f, "%d %d\n", &num_elements, find); + int32_t* arr = malloc(sizeof(int32_t) * num_elements); + for (i = 0; i < num_elements; i++) { + fscanf(f, "%d\n", &key); + arr[i] = key; + } + *num = num_elements; + fclose(f); + return arr; +} + +void swap(int* a, int* b) { + int temp = *a; + *a = *b; + *b = temp; +} + +// int partition(int arr[], int low, int high) { +// int pivot = arr[high]; +// int i = low - 1; +// for (int j = low; j < high; j++) { +// if (arr[j] < pivot) { +// i++; +// swap(arr + i, arr + j); +// } +// } +// swap(arr[i + 1], arr[high]); +// return i + 1; +// } + +// void quickSort(int arr[], int low, int high) { +// if (low < high) { +// int pi = partition(arr, low, high); +// quickSort(arr, low, pi - 1); +// quickSort(arr, pi + 1, high); +// } +// } + +void printArray(int* arr, int size) { + for (int i = 0; i < size; i++) { + printf("%d\n",arr[i]); + } +} +void selectionSort(int* arr, int n) { + for (int i = 0; i < n - 1; ++i) { + int minIndex = i; + for (int j = i + 1; j < n; ++j) { + if (arr[j] < arr[minIndex]) { + minIndex = j; + } + } + if (minIndex != i) { + swap(arr + i, arr + minIndex); + } + } +} +// int main() { +// int arr[] = {12, 11, 13, 5, 6, 7}; +// int n = num_elements; +// std::cout << "Original array: \n"; +// printArray(arr, n); +// quickSort(arr, 0, n - 1); +// std::cout << "Sorted array: \n"; +// printArray(arr, n); +// return 0; +// } + +int main(int argc, char** argv) { + if(argc < 2) { + printf("Usage: ./maze \n"); + return -1; + } + int32_t* arr = NULL; + uint32_t find = 0; + uint32_t num_elements = 0; + + arr = import_arr(argv[1], &find, &num_elements); + //printf("Reading Tree:\n"); + //print(root); + selectionSort(arr, num_elements); + //printf("\nBeginning C Search\n"); + printf("search find %d: %d\n", find, binarySearch(arr, find, 0, num_elements)); + printf("search find %d: %d\n", find, binarySearch(arr, find, 0, num_elements)); + //printf("Beginning ASM Search\n"); + // printf("search find %d: %d\n", find, search_asm(root, find)); + return 0; +} diff --git a/ps1/p3/Makefile b/ps1/p3/Makefile new file mode 100644 index 0000000..02870a4 --- /dev/null +++ b/ps1/p3/Makefile @@ -0,0 +1,31 @@ +# Makefile ASM to C +# Aamir Hasan +# 8/30/20 + + +PROG := mystery + +CFLAGS += -m32 -Wall -std=c99 + +.PHONY: clean + +all: CFLAGS += -O0 +all: $(PROG) + +debug: CFLAGS += -O0 -g +debug: $(PROG) + +$(PROG): mystery_asm.o mystery.o main.o + $(CC) -m32 $^ -o $@ + +mystery_asm.o: mystery_asm.S + $(CC) $(CFLAGS) -c $< -o $@ + +mystery.o: mystery.c + $(CC) $(CFLAGS) -c $< -o $@ + +main.o: main.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f *.o $(PROG) diff --git a/ps1/p3/grade.txt b/ps1/p3/grade.txt new file mode 100644 index 0000000..b1b4970 --- /dev/null +++ b/ps1/p3/grade.txt @@ -0,0 +1,2 @@ +Grades: +10/10 diff --git a/ps1/p3/input_1.txt b/ps1/p3/input_1.txt new file mode 100644 index 0000000..a626cdf --- /dev/null +++ b/ps1/p3/input_1.txt @@ -0,0 +1 @@ +0 1 89 diff --git a/ps1/p3/input_2.txt b/ps1/p3/input_2.txt new file mode 100644 index 0000000..343ec8a --- /dev/null +++ b/ps1/p3/input_2.txt @@ -0,0 +1 @@ +1 2 14 diff --git a/ps1/p3/input_3.txt b/ps1/p3/input_3.txt new file mode 100644 index 0000000..c6304c2 --- /dev/null +++ b/ps1/p3/input_3.txt @@ -0,0 +1 @@ +2 23 4 diff --git a/ps1/p3/main.c b/ps1/p3/main.c new file mode 100644 index 0000000..cc26106 --- /dev/null +++ b/ps1/p3/main.c @@ -0,0 +1,85 @@ +/* + * tab:2 + * + * main.c - I/O and P3 setup + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF ILLINOIS BE LIABLE TO + * ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, + * EVEN IF THE AUTHOR AND/OR THE UNIVERSITY OF ILLINOIS HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR AND THE UNIVERSITY OF ILLINOIS SPECIFICALLY DISCLAIM ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND NEITHER THE AUTHOR NOR + * THE UNIVERSITY OF ILLINOIS HAS ANY OBLIGATION TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Author: Aamir Hasan + * Version: 1 + * Creation Date: Sun Aug 30 2020 + * Filename: main.c + * History: + * AH 1 Sun Aug 30 2020 + * First written. + */ + +#include +#include +#include + +#include "mystery.h" + +#define MAX_LENGTH 500 + +uint32_t import(char* infile, uint32_t* op, uint32_t* x, uint32_t* y) { + FILE* f = fopen(infile, "r"); + if (f == NULL) return -1; + fscanf(f, "%d %d %d\n", op, x, y); + fclose(f); + return 0; +} + + + +int main(int argc, char** argv) { + if(argc < 2) { + printf("Usage: ./mystery \n"); + return -1; + } + uint32_t x = 0; + uint32_t y = 0; + uint32_t opcode = 0; + uint32_t out = 0; + + import(argv[1], &opcode, &x, &y); + if(opcode ==0 ) { + if (y > MAX_LENGTH) { + printf("Error: x is too large\n"); + return -1; + } + uint32_t* ptr = malloc(sizeof(uint32_t) * MAX_LENGTH); + for(int i=0; i +#include +#include + +// mystery_asm +// The mystery function +extern int32_t mystery_asm(uint32_t opcode, uint32_t x, uint32_t y); + + +// mystery_c +// Same as above +int32_t mystery_c(uint32_t opcode, uint32_t x, uint32_t y); + + +#endif \ No newline at end of file diff --git a/ps1/p3/mystery_asm.S b/ps1/p3/mystery_asm.S new file mode 100644 index 0000000..e78c36b --- /dev/null +++ b/ps1/p3/mystery_asm.S @@ -0,0 +1,83 @@ + +/* + * tab:2 + * + * mystery_asm.S - Assembly mystery + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF ILLINOIS BE LIABLE TO + * ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, + * EVEN IF THE AUTHOR AND/OR THE UNIVERSITY OF ILLINOIS HAS BEEN ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE AUTHOR AND THE UNIVERSITY OF ILLINOIS SPECIFICALLY DISCLAIM ANY + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND NEITHER THE AUTHOR NOR + * THE UNIVERSITY OF ILLINOIS HAS ANY OBLIGATION TO PROVIDE MAINTENANCE, + * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + * Author: Aamir Hasan + * Version: 1 + * Creation Date: Sun Aug 30 2020 + * Filename: mystery_asm.S + * History: + * AH 1 Sun Aug 30 2020 + * First written. + */ + + +# mystery (Assembly) +# +# Registers: +# eax - Return Value +# ebx - x +# ecx - y +# esi - opcode + +.GLOBAL mystery_asm + +mystery_asm: + pushl %ebp + movl %esp, %ebp + pushl %ebx + pushl %esi + pushl %edi + movl 8(%ebp), %esi + movl 12(%ebp), %ebx + movl 16(%ebp), %ecx + cmpl $2, %esi + jg DEFAULT + cmpl $0, %esi + jl DEFAULT + jmp *jumptable(,%esi,4) +OP1: + movl (%ebx, %ecx, 4), %eax + jmp FINISH +OP2: + leal (%ebx, %ecx, 8), %eax + subl %ecx, %eax + jmp FINISH +OP3: + movl %ebx, %eax + xorl %edx, %edx + divl %ecx + movl %edx, %eax + jmp FINISH + +DEFAULT: + movl $0xBAD, %eax +FINISH: + popl %edi + popl %esi + popl %ebx + leave + ret + +jumptable: + .long OP1, OP2, OP3 diff --git a/ps1/partners.txt b/ps1/partners.txt new file mode 100644 index 0000000..9e93840 --- /dev/null +++ b/ps1/partners.txt @@ -0,0 +1,7 @@ +yuxuan42 +xingyul6 +xuhangx2 +boweny6 +jjczyz2 +iramo3 +Jbiel2 \ No newline at end of file