From 6fc2e076cdb01ec7ca587a1c4093e57d0bf750e9 Mon Sep 17 00:00:00 2001 From: aalsaqer <aalsaqer@student.unimelb.edu.au> Date: Sat, 1 Sep 2018 14:49:39 +1000 Subject: [PATCH] All examples related to errors --- examples/div_test.s | 7 +++++ examples/invalidInstrctuinLength.s | 7 +++++ examples/invalidInstrctuinLength2.s | 7 +++++ examples/invalidInstructions.s | 7 +++++ examples/invalidJMP.s | 8 ++++++ examples/invalidJZ.s | 9 +++++++ examples/multiReturn.s | 42 +++++++++++++++++++++++++++++ examples/noReturn.s | 6 +++++ examples/registerNotInRage.s | 7 +++++ examples/registerNotInRage2.s | 7 +++++ examples/validJMP1.s | 10 +++++++ examples/valueNotInRage.s | 7 +++++ examples/valueNotInRage2.s | 7 +++++ 13 files changed, 131 insertions(+) create mode 100644 examples/div_test.s create mode 100644 examples/invalidInstrctuinLength.s create mode 100644 examples/invalidInstrctuinLength2.s create mode 100644 examples/invalidInstructions.s create mode 100644 examples/invalidJMP.s create mode 100644 examples/invalidJZ.s create mode 100644 examples/multiReturn.s create mode 100644 examples/noReturn.s create mode 100644 examples/registerNotInRage.s create mode 100644 examples/registerNotInRage2.s create mode 100644 examples/validJMP1.s create mode 100644 examples/valueNotInRage.s create mode 100644 examples/valueNotInRage2.s diff --git a/examples/div_test.s b/examples/div_test.s new file mode 100644 index 0000000..e2a50a4 --- /dev/null +++ b/examples/div_test.s @@ -0,0 +1,7 @@ + ;; DIV statement to test for zero divide + MOV R3 10 ; N = 10 + MOV R2 0 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file diff --git a/examples/invalidInstrctuinLength.s b/examples/invalidInstrctuinLength.s new file mode 100644 index 0000000..41323aa --- /dev/null +++ b/examples/invalidInstrctuinLength.s @@ -0,0 +1,7 @@ + ;; invalid instruction test for length of the inputs + MOV R3 10 ; N = 10 + MOV R2 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file diff --git a/examples/invalidInstrctuinLength2.s b/examples/invalidInstrctuinLength2.s new file mode 100644 index 0000000..5496d98 --- /dev/null +++ b/examples/invalidInstrctuinLength2.s @@ -0,0 +1,7 @@ + ;; invalid instruction test for length of the inputs + MOV R3 10 + MOV R2 10 10 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file diff --git a/examples/invalidInstructions.s b/examples/invalidInstructions.s new file mode 100644 index 0000000..b4bf994 --- /dev/null +++ b/examples/invalidInstructions.s @@ -0,0 +1,7 @@ + ;; Invalid instruction not in the list + MVo R3 10 ; N = 10 + MOV R2 0 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file diff --git a/examples/invalidJMP.s b/examples/invalidJMP.s new file mode 100644 index 0000000..a8d68ce --- /dev/null +++ b/examples/invalidJMP.s @@ -0,0 +1,8 @@ + ;; JMP with jumping with invalid register value + MOV R3 -100 + MOV R2 10 + MOV R4 100 + + DIV R4 R3 R2 + JMP -10000 + RET R4 \ No newline at end of file diff --git a/examples/invalidJZ.s b/examples/invalidJZ.s new file mode 100644 index 0000000..c431909 --- /dev/null +++ b/examples/invalidJZ.s @@ -0,0 +1,9 @@ + ;; JZ with jumping with invalid register value + + MOV R3 10 + MOV R2 10 + MOV R4 100 + + SUB R4 R3 R2 + JZ R4 10000 + RET R4 \ No newline at end of file diff --git a/examples/multiReturn.s b/examples/multiReturn.s new file mode 100644 index 0000000..498a661 --- /dev/null +++ b/examples/multiReturn.s @@ -0,0 +1,42 @@ + ;; Statement with multiple RET statements + ;; array program. Fills an array with the values 0 ... N-1 + ;; and then interates through the array, summing its elements + + ;; global constants: + ;; R3 holds 'N', the length of the array + ;; R2 holds 1, the increment value used below + MOV R3 10 ; N = 10 + MOV R2 1 ; + + ;; create the array + ;; local variables + ;; R1 holds 'i', which is a counter from 0 .. N-1 + ;; R0 holds 'p', the address of the array's ith element + MOV R1 0 ; i = 0; + MOV R0 100 + + SUB R4 R3 R1 ; while(i != N) + JZ R4 5 ; { + STR R0 0 R1 ; *p = i; + ADD R1 R1 R2 ; i = i + 1; + ADD R0 R0 R2 ; p = p + 1; + JMP -5 ; } + + ;; sum up the array + ;; local variables + ;; R1 holds 'i', which is a counter from 0 .. N-1 + ;; R0 holds 'p', the address of the array's ith element + ;; R5 holds 'sum', which always holds the sum of the array's first i elements + MOV R1 0 ; i = 0; + MOV R0 100 + MOV R5 0 ; sum = 0; + RET R5 + + SUB R4 R3 R1 ; while(i != N) + JZ R4 6 ; { + LDR R4 R0 0 ; + ADD R5 R5 R4 ; sum = sum + *p; + ADD R0 R0 R2 ; p = p + 1; + ADD R1 R1 R2 ; i = i + 1; + JMP -6 ; } + RET R5 ; return sum; diff --git a/examples/noReturn.s b/examples/noReturn.s new file mode 100644 index 0000000..2e01465 --- /dev/null +++ b/examples/noReturn.s @@ -0,0 +1,6 @@ + ;; No Return value + MOV R3 10 + MOV R2 10 + MOV R4 100 + + DIV R4 R3 R2 \ No newline at end of file diff --git a/examples/registerNotInRage.s b/examples/registerNotInRage.s new file mode 100644 index 0000000..4c84fa6 --- /dev/null +++ b/examples/registerNotInRage.s @@ -0,0 +1,7 @@ + ;; Register value not in range of 0...31 + MOV R33 10 ; N = 10 + MOV R2 0 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file diff --git a/examples/registerNotInRage2.s b/examples/registerNotInRage2.s new file mode 100644 index 0000000..83ef0ae --- /dev/null +++ b/examples/registerNotInRage2.s @@ -0,0 +1,7 @@ + ;; Register value not in range of 0...31 + MOV R-2 10 ; N = 10 + MOV R2 0 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file diff --git a/examples/validJMP1.s b/examples/validJMP1.s new file mode 100644 index 0000000..a966760 --- /dev/null +++ b/examples/validJMP1.s @@ -0,0 +1,10 @@ + ;; JMP with jumping with invalid register value + MOV R3 -100 + MOV R2 10 + MOV R4 100 + + DIV R4 R3 R2 + JMP 1 + ADD R4 R3 R4 + MOV R5 100 + RET R5 \ No newline at end of file diff --git a/examples/valueNotInRage.s b/examples/valueNotInRage.s new file mode 100644 index 0000000..e1aefc9 --- /dev/null +++ b/examples/valueNotInRage.s @@ -0,0 +1,7 @@ + ;; value not in range of -65536.... 65535 + MOV R3 70000 ; N = 10 + MOV R2 0 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file diff --git a/examples/valueNotInRage2.s b/examples/valueNotInRage2.s new file mode 100644 index 0000000..42d8efb --- /dev/null +++ b/examples/valueNotInRage2.s @@ -0,0 +1,7 @@ + ;; value not in range of -65536.... 65535 + MOV R3 -70000 ; N = 10 + MOV R2 0 ; + MOV R4 100 + + DIV R4 R3 R2 + RET R4 \ No newline at end of file -- GitLab