diff --git a/examples/B10_1.s b/examples/B10_1.s new file mode 100644 index 0000000000000000000000000000000000000000..7369a735590195534fc81b90ecbbaaa8fd7efdb1 --- /dev/null +++ b/examples/B10_1.s @@ -0,0 +1,8 @@ +MOV R1 -1 +MOV R2 2 +STR R1 1 R2 +LDR R3 R1 1 +RET R3 + + + diff --git a/examples/B10_2.s b/examples/B10_2.s new file mode 100644 index 0000000000000000000000000000000000000000..6d8a4f25baa5dccd66e7be3f18614f81119eefc0 --- /dev/null +++ b/examples/B10_2.s @@ -0,0 +1,8 @@ +MOV R1 65535 +MOV R2 2 +STR R1 0 R2 +LDR R3 R1 0 +RET R3 + + + diff --git a/examples/B10_3.s b/examples/B10_3.s new file mode 100644 index 0000000000000000000000000000000000000000..6bb430f724c99afb869d240648edc45188efc81a --- /dev/null +++ b/examples/B10_3.s @@ -0,0 +1,8 @@ +MOV R1 -1 +MOV R2 2 +STR R1 0 R2 +LDR R3 R1 1 +RET R3 + + + diff --git a/examples/B10_4.s b/examples/B10_4.s new file mode 100644 index 0000000000000000000000000000000000000000..8421062b664abb2a5352c9be0121eeb0e5ce1b94 --- /dev/null +++ b/examples/B10_4.s @@ -0,0 +1,8 @@ +MOV R1 -1 +MOV R2 2 +STR R1 1 R2 +LDR R3 R1 0 +RET R3 + + + diff --git a/examples/B10_5.s b/examples/B10_5.s new file mode 100644 index 0000000000000000000000000000000000000000..c4c5fb6f074800379d312e5958924d597e18977f --- /dev/null +++ b/examples/B10_5.s @@ -0,0 +1,8 @@ +MOV R1 65535 +MOV R2 2 +STR R1 1 R2 +LDR R3 R1 0 +RET R3 + + + diff --git a/examples/B10_6.s b/examples/B10_6.s new file mode 100644 index 0000000000000000000000000000000000000000..02270f8e7b4bdca374c50315928afd5e0d296dd9 --- /dev/null +++ b/examples/B10_6.s @@ -0,0 +1,8 @@ +MOV R1 65535 +MOV R2 2 +STR R1 0 R2 +LDR R3 R1 1 +RET R3 + + + diff --git a/examples/B11_1.s b/examples/B11_1.s new file mode 100644 index 0000000000000000000000000000000000000000..9b99e38ce236619f982318e2f85a7e5bbdc4eac7 --- /dev/null +++ b/examples/B11_1.s @@ -0,0 +1,4 @@ +MOV R0 2 +JMP 1 +ADD R0 R1 R0 +RET R0 diff --git a/examples/B11_2.s b/examples/B11_2.s new file mode 100644 index 0000000000000000000000000000000000000000..a447970844c4406ff940a56a7a6e219ae6a6070d --- /dev/null +++ b/examples/B11_2.s @@ -0,0 +1,3 @@ +MOV R0 2 +JMP 0 +RET R0 diff --git a/examples/B11_3.s b/examples/B11_3.s new file mode 100644 index 0000000000000000000000000000000000000000..88be6941e1a959811e50080ccaac016c24b478cb --- /dev/null +++ b/examples/B11_3.s @@ -0,0 +1,7 @@ +MOV R1 4 +MOV R2 2 +SUB R1 R1 R2 +JZ R1 3 +JZ R4 -2 +JMP -1 +RET R2 diff --git a/examples/B11_4.s b/examples/B11_4.s new file mode 100644 index 0000000000000000000000000000000000000000..c8b476abb032a508b2b48b2153c122551f3e2d58 --- /dev/null +++ b/examples/B11_4.s @@ -0,0 +1,5 @@ +MOV R0 2 +JMP 2 +ADD R0 R0 R1 +MUL R0 R0 R0 +RET R0 diff --git a/examples/B12_1.s b/examples/B12_1.s new file mode 100644 index 0000000000000000000000000000000000000000..2fe8eb5855c048fc068c939d6ac06ef3bfc89a9a --- /dev/null +++ b/examples/B12_1.s @@ -0,0 +1,7 @@ +MOV R0 2 +ADD R1 R3 R0 +SUB R1 R1 R1 +JMP -4 +ADD R0 R0 R1 +MUL R0 R0 R0 +RET R0 \ No newline at end of file diff --git a/examples/B12_2.s b/examples/B12_2.s new file mode 100644 index 0000000000000000000000000000000000000000..3a7d83a905f61be11d359b8b696f9bd2d47febfc --- /dev/null +++ b/examples/B12_2.s @@ -0,0 +1,7 @@ +MOV R0 2 +ADD R1 R3 R0 +SUB R1 R1 R1 +JMP 3 +ADD R0 R0 R1 +MUL R0 R0 R0 +RET R0 diff --git a/examples/B12_3.s b/examples/B12_3.s new file mode 100644 index 0000000000000000000000000000000000000000..2fe8eb5855c048fc068c939d6ac06ef3bfc89a9a --- /dev/null +++ b/examples/B12_3.s @@ -0,0 +1,7 @@ +MOV R0 2 +ADD R1 R3 R0 +SUB R1 R1 R1 +JMP -4 +ADD R0 R0 R1 +MUL R0 R0 R0 +RET R0 \ No newline at end of file diff --git a/examples/B12_4.s b/examples/B12_4.s new file mode 100644 index 0000000000000000000000000000000000000000..fd099fe289690bc770877dfae9d1a397ba3c2add --- /dev/null +++ b/examples/B12_4.s @@ -0,0 +1,7 @@ +MOV R0 2 +ADD R1 R3 R0 +SUB R1 R1 R1 +JMP 4 +ADD R0 R0 R1 +MUL R0 R0 R0 +RET R0 diff --git a/examples/B13_1.s b/examples/B13_1.s new file mode 100644 index 0000000000000000000000000000000000000000..72d0dbe4cc1723fff4a0552151b5b957c4b582a2 --- /dev/null +++ b/examples/B13_1.s @@ -0,0 +1,4 @@ +MOV R0 0 +JZ R0 2 +ADD R0 R1 R0 +RET R0 diff --git a/examples/B13_2.s b/examples/B13_2.s new file mode 100644 index 0000000000000000000000000000000000000000..abec61ec4f5e7fa006ca0ccb7f295529eb7e4518 --- /dev/null +++ b/examples/B13_2.s @@ -0,0 +1,4 @@ +MOV R0 -1 +JZ R0 2 +ADD R0 R1 R0 +RET R0 diff --git a/examples/B13_3.s b/examples/B13_3.s new file mode 100644 index 0000000000000000000000000000000000000000..f2abd6e8a8c2d90f0eba772a134a7c3ff4db3bf2 --- /dev/null +++ b/examples/B13_3.s @@ -0,0 +1,5 @@ +MOV R0 1 +MOV R2 2 +JZ R1 2 +SUB R1 R1 R2 +RET R2 diff --git a/examples/B2_1.s b/examples/B2_1.s new file mode 100644 index 0000000000000000000000000000000000000000..7af5a7192b54c6453b1ac5af57fc5d6e37a3180d --- /dev/null +++ b/examples/B2_1.s @@ -0,0 +1,5 @@ +MOV R2 30 +MOV R31 10 +MOV R0 6 +DIV R31 R2 R0 +RET R31 diff --git a/examples/B2_2.s b/examples/B2_2.s new file mode 100644 index 0000000000000000000000000000000000000000..6549102c9a87b9c15f3786859fd52c044b4bd1e6 --- /dev/null +++ b/examples/B2_2.s @@ -0,0 +1,4 @@ +MOV R2 2 +DIV R3 R2 R-1 +RET R3 + diff --git a/examples/B2_3.s b/examples/B2_3.s new file mode 100644 index 0000000000000000000000000000000000000000..552b1c9f9cc1b198990e2cfb45bd20b5e58d6e63 --- /dev/null +++ b/examples/B2_3.s @@ -0,0 +1,3 @@ +MOV R2 2 +DIV R3 R2 R32 +RET R3 diff --git a/examples/B3_1.s b/examples/B3_1.s new file mode 100644 index 0000000000000000000000000000000000000000..02c9dd6d6eda6f6c960dfd1117c1321b823673cb --- /dev/null +++ b/examples/B3_1.s @@ -0,0 +1,4 @@ +MOV R2 2 +MOV R31 10 +SUB R31 R2 R0 +RET R31 diff --git a/examples/B3_2.s b/examples/B3_2.s new file mode 100644 index 0000000000000000000000000000000000000000..83953c6040463550b08841cd1c118d34e1e1b182 --- /dev/null +++ b/examples/B3_2.s @@ -0,0 +1,4 @@ +MOV R2 2 +SUB R3 R2 R-1 +RET R3 + diff --git a/examples/B3_3.s b/examples/B3_3.s new file mode 100644 index 0000000000000000000000000000000000000000..713e4aa26a9c00c07684b409e4bdc82f45965b12 --- /dev/null +++ b/examples/B3_3.s @@ -0,0 +1,3 @@ +MOV R2 2 +SUB R3 R2 R32 +RET R3 diff --git a/examples/B4_1.s b/examples/B4_1.s new file mode 100644 index 0000000000000000000000000000000000000000..0006317ae5ae95e2268b9e43631b47a4ec2d3af0 --- /dev/null +++ b/examples/B4_1.s @@ -0,0 +1,4 @@ +MOV R2 2 +MOV R31 10 +MUL R31 R2 R0 +RET R31 diff --git a/examples/B4_2.s b/examples/B4_2.s new file mode 100644 index 0000000000000000000000000000000000000000..0b7e82c43b82ddad62b6ae989a0689de7bf69b3f --- /dev/null +++ b/examples/B4_2.s @@ -0,0 +1,4 @@ +MOV R2 2 +MUL R3 R2 R-1 +RET R3 + diff --git a/examples/B4_3.s b/examples/B4_3.s new file mode 100644 index 0000000000000000000000000000000000000000..d7600f1ab80c84f4c46d01ce9b3d6a9b6209389e --- /dev/null +++ b/examples/B4_3.s @@ -0,0 +1,3 @@ +MOV R2 2 +MUL R3 R2 R32 +RET R3 diff --git a/examples/B5_1.s b/examples/B5_1.s new file mode 100644 index 0000000000000000000000000000000000000000..15fd63c88d09ee381ddad56553d0b767c8129408 --- /dev/null +++ b/examples/B5_1.s @@ -0,0 +1,4 @@ +MOV R2 2 +MOV R31 10 +ADD R31 R2 R0 +RET R31 diff --git a/examples/B5_2.s b/examples/B5_2.s new file mode 100644 index 0000000000000000000000000000000000000000..485b1f5fb7f911e98250ceb160e05e46f57b2f08 --- /dev/null +++ b/examples/B5_2.s @@ -0,0 +1,4 @@ +MOV R2 2 +ADD R3 R2 R-1 +RET R3 + diff --git a/examples/B5_3.s b/examples/B5_3.s new file mode 100644 index 0000000000000000000000000000000000000000..28adb180c998eee10dd084b70da2d8acfa159b9a --- /dev/null +++ b/examples/B5_3.s @@ -0,0 +1,3 @@ +MOV R2 2 +ADD R3 R2 R32 +RET R3 diff --git a/examples/B6_1.s b/examples/B6_1.s new file mode 100644 index 0000000000000000000000000000000000000000..303e0f084e070b4aa7013fae31c44c7915b1dce5 --- /dev/null +++ b/examples/B6_1.s @@ -0,0 +1,3 @@ +MOV R0 2 +RET R0 + diff --git a/examples/B6_2.s b/examples/B6_2.s new file mode 100644 index 0000000000000000000000000000000000000000..17c78cbbb3495d1bd3de4510d130491758b92bb3 --- /dev/null +++ b/examples/B6_2.s @@ -0,0 +1,4 @@ +MOV R31 2 +RET R31 + + diff --git a/examples/B6_3.s b/examples/B6_3.s new file mode 100644 index 0000000000000000000000000000000000000000..3216ba669b50c0740725c5b6553423e9a797e85a --- /dev/null +++ b/examples/B6_3.s @@ -0,0 +1,2 @@ +MOV R-1 2 +RET R31 diff --git a/examples/B6_4.s b/examples/B6_4.s new file mode 100644 index 0000000000000000000000000000000000000000..a3d6aceef5eb7dd9e7146d45d90b832686c68e7e --- /dev/null +++ b/examples/B6_4.s @@ -0,0 +1,2 @@ +MOV R32 2 +RET R31 diff --git a/examples/B7_1.s b/examples/B7_1.s new file mode 100644 index 0000000000000000000000000000000000000000..054b7c697be25bc2d8968304ae2066af2527caa8 --- /dev/null +++ b/examples/B7_1.s @@ -0,0 +1,3 @@ +MOV R1 -65535 +RET R1 + diff --git a/examples/B7_2.s b/examples/B7_2.s new file mode 100644 index 0000000000000000000000000000000000000000..ae1041a7f9c390ad3b72823bde675c7a9e109f09 --- /dev/null +++ b/examples/B7_2.s @@ -0,0 +1,4 @@ +MOV R1 65535 +RET R1 + + diff --git a/examples/B7_3.s b/examples/B7_3.s new file mode 100644 index 0000000000000000000000000000000000000000..74be38ca0c9124d614e804e614836c1f2a05a9b9 --- /dev/null +++ b/examples/B7_3.s @@ -0,0 +1,2 @@ +MOV R1 -65536 +RET R1 diff --git a/examples/B7_4.s b/examples/B7_4.s new file mode 100644 index 0000000000000000000000000000000000000000..73b01790c53281d00226cdc3b962ad0613dd73a8 --- /dev/null +++ b/examples/B7_4.s @@ -0,0 +1,2 @@ +MOV R1 65536 +RET R1 \ No newline at end of file diff --git a/examples/B8_1.s b/examples/B8_1.s new file mode 100644 index 0000000000000000000000000000000000000000..76c9fdb8b6d427e70b92b4a1e0bd1ffc616a38c4 --- /dev/null +++ b/examples/B8_1.s @@ -0,0 +1,3 @@ +LDR R0 R31 2 +RET R0 + diff --git a/examples/B8_2.s b/examples/B8_2.s new file mode 100644 index 0000000000000000000000000000000000000000..4dcbb5388892cd4e242be47f0c796fe2af453267 --- /dev/null +++ b/examples/B8_2.s @@ -0,0 +1,2 @@ +LDR R0 R32 2 +RET R0 \ No newline at end of file diff --git a/examples/B8_3.s b/examples/B8_3.s new file mode 100644 index 0000000000000000000000000000000000000000..ba34327aa8fa3823d55a48c3ca345da39dae00a4 --- /dev/null +++ b/examples/B8_3.s @@ -0,0 +1,2 @@ +LDR R-1 R31 2 +RET R0 \ No newline at end of file diff --git a/examples/B8_4.s b/examples/B8_4.s new file mode 100644 index 0000000000000000000000000000000000000000..a93250064cdbd118bc09094afe7175c121b5d5c6 --- /dev/null +++ b/examples/B8_4.s @@ -0,0 +1,2 @@ +STR R0 2 R31 +RET R0 diff --git a/examples/B8_5.s b/examples/B8_5.s new file mode 100644 index 0000000000000000000000000000000000000000..e9296d362e6742371dd94a67385a49f3ae1a55bd --- /dev/null +++ b/examples/B8_5.s @@ -0,0 +1,2 @@ +STR R0 2 R32 +RET R0 \ No newline at end of file diff --git a/examples/B8_6.s b/examples/B8_6.s new file mode 100644 index 0000000000000000000000000000000000000000..90e2920af3f855287cdde7e6e51b34705a1e9442 --- /dev/null +++ b/examples/B8_6.s @@ -0,0 +1,2 @@ +STR R-1 2 R31 +RET R0 \ No newline at end of file diff --git a/examples/B9_1.s b/examples/B9_1.s new file mode 100644 index 0000000000000000000000000000000000000000..9a0a1db9f2b27b54795b47f0d94715c565ab550c --- /dev/null +++ b/examples/B9_1.s @@ -0,0 +1,5 @@ +STR R0 -65535 R31 +LDR R1 R0 65535 +RET R1 + + diff --git a/examples/B9_2.s b/examples/B9_2.s new file mode 100644 index 0000000000000000000000000000000000000000..804d2bf44babae4206f7b52c60c76c85a0469c12 --- /dev/null +++ b/examples/B9_2.s @@ -0,0 +1,5 @@ +STR R0 65535 R31 +LDR R0 R31 -65535 +RET R0 + + diff --git a/examples/B9_3.s b/examples/B9_3.s new file mode 100644 index 0000000000000000000000000000000000000000..5a0c4539cb4ae8193795efdc8f269ee1a2670ede --- /dev/null +++ b/examples/B9_3.s @@ -0,0 +1,5 @@ +STR R0 -65536 R31 +LDR R0 R31 65535 +RET R0 + + diff --git a/examples/B9_4.s b/examples/B9_4.s new file mode 100644 index 0000000000000000000000000000000000000000..c021cd584ba93c406af973eb67ffb5785b5538b9 --- /dev/null +++ b/examples/B9_4.s @@ -0,0 +1,5 @@ +STR R0 -65535 R31 +LDR R0 R31 65536 +RET R0 + + diff --git a/examples/B9_5.s b/examples/B9_5.s new file mode 100644 index 0000000000000000000000000000000000000000..7b0df7f26500062b833646c4dc01bb9a1070a86e --- /dev/null +++ b/examples/B9_5.s @@ -0,0 +1,5 @@ +STR R0 65536 R31 +LDR R0 R31 -65535 +RET R0 + + diff --git a/examples/B9_6.s b/examples/B9_6.s new file mode 100644 index 0000000000000000000000000000000000000000..4a23d8bcd7b9a501a1c3bd85e534edf2a4b38bec --- /dev/null +++ b/examples/B9_6.s @@ -0,0 +1,5 @@ +STR R0 -65535 R31 +LDR R0 R31 -65536 +RET R0 + + diff --git a/examples/EC2-1.s b/examples/EC2-1.s new file mode 100644 index 0000000000000000000000000000000000000000..8469c095a4c35c5656116ce51ea92be053fe2aef --- /dev/null +++ b/examples/EC2-1.s @@ -0,0 +1 @@ +RET R-1 \ No newline at end of file diff --git a/examples/EC2-10.s b/examples/EC2-10.s new file mode 100644 index 0000000000000000000000000000000000000000..2a754406226e8eb93bd8fad863f7a7f46d275cc8 --- /dev/null +++ b/examples/EC2-10.s @@ -0,0 +1,4 @@ +MOV R2 2 +MOV R3 3 +ADD R1 R2 R3 +RET R1 \ No newline at end of file diff --git a/examples/EC2-11.s b/examples/EC2-11.s new file mode 100644 index 0000000000000000000000000000000000000000..be4ba41dd84cc6681531478fc2dfe430fa29f9e0 --- /dev/null +++ b/examples/EC2-11.s @@ -0,0 +1,4 @@ +MOV R2 5 +MOV R1 3 +RET R2 +RET R1 \ No newline at end of file diff --git a/examples/EC2-12.s b/examples/EC2-12.s new file mode 100644 index 0000000000000000000000000000000000000000..c54cd86224840f944e78c6221efa89458adfa123 --- /dev/null +++ b/examples/EC2-12.s @@ -0,0 +1,2 @@ +MOV R10 -65536 +RET R10 \ No newline at end of file diff --git a/examples/EC2-13.s b/examples/EC2-13.s new file mode 100644 index 0000000000000000000000000000000000000000..a2049c12ad865d99a8a719e895058468d7308d8f --- /dev/null +++ b/examples/EC2-13.s @@ -0,0 +1,2 @@ +MOV R11 -65535 +RET R11 \ No newline at end of file diff --git a/examples/EC2-14.s b/examples/EC2-14.s new file mode 100644 index 0000000000000000000000000000000000000000..a01ac78ad994b7fdb9e6e245a7e126162ebcdfd3 --- /dev/null +++ b/examples/EC2-14.s @@ -0,0 +1,2 @@ +MOV R12 65536 +RET R12 \ No newline at end of file diff --git a/examples/EC2-15.s b/examples/EC2-15.s new file mode 100644 index 0000000000000000000000000000000000000000..2b94b9a4608aaabf9417e85519b99bf8a6e585c7 --- /dev/null +++ b/examples/EC2-15.s @@ -0,0 +1,5 @@ +MOV R1 100 +MOV R2 5 +STR R2 1 R1 +LDR R4 R2 1 +RET R4 diff --git a/examples/EC2-16.s b/examples/EC2-16.s new file mode 100644 index 0000000000000000000000000000000000000000..f7fc5b75b8d360463b9e5bf42633739d874a7cbd --- /dev/null +++ b/examples/EC2-16.s @@ -0,0 +1,5 @@ +MOV R1 100 +MOV R2 -2 +STR R2 1 R1 +LDR R4 R2 1 +RET R4 diff --git a/examples/EC2-17.s b/examples/EC2-17.s new file mode 100644 index 0000000000000000000000000000000000000000..2b94b9a4608aaabf9417e85519b99bf8a6e585c7 --- /dev/null +++ b/examples/EC2-17.s @@ -0,0 +1,5 @@ +MOV R1 100 +MOV R2 5 +STR R2 1 R1 +LDR R4 R2 1 +RET R4 diff --git a/examples/EC2-18.s b/examples/EC2-18.s new file mode 100644 index 0000000000000000000000000000000000000000..85a086d588d29b875c7a830b9c09ee6430ef4429 --- /dev/null +++ b/examples/EC2-18.s @@ -0,0 +1,5 @@ +MOV R1 100 +MOV R2 65530 +STR R2 10 R1 +LDR R4 R2 1 +RET R4 diff --git a/examples/EC2-19.s b/examples/EC2-19.s new file mode 100644 index 0000000000000000000000000000000000000000..a7174e374ded8ac0bc2a759b7b185f2287461d1e --- /dev/null +++ b/examples/EC2-19.s @@ -0,0 +1,3 @@ +MOV R1 10 +JMP 0 +RET R1 diff --git a/examples/EC2-2.s b/examples/EC2-2.s new file mode 100644 index 0000000000000000000000000000000000000000..8604c4db1ae8fa7d6b738bf87f8af4a0ed43b652 --- /dev/null +++ b/examples/EC2-2.s @@ -0,0 +1 @@ +RET R0 \ No newline at end of file diff --git a/examples/EC2-20.s b/examples/EC2-20.s new file mode 100644 index 0000000000000000000000000000000000000000..c2c9b703fc16e68861268317226e915b6a12cb60 --- /dev/null +++ b/examples/EC2-20.s @@ -0,0 +1,3 @@ +MOV R1 10 +JMP 1 +RET R1 diff --git a/examples/EC2-21.s b/examples/EC2-21.s new file mode 100644 index 0000000000000000000000000000000000000000..8ec472ce0c219c7240213b85a16a4e0b69a00a20 --- /dev/null +++ b/examples/EC2-21.s @@ -0,0 +1,9 @@ +MOV R1 10 +MOV R3 12 +MOV R2 1 +SUB R4 R3 R1 +JMP 3 +ADD R2 R1 R2 +SUB R2 R1 R2 +MUL R10 R2 R3 +RET R2 \ No newline at end of file diff --git a/examples/EC2-22.s b/examples/EC2-22.s new file mode 100644 index 0000000000000000000000000000000000000000..8268ea0a03619ec66a9f4fbece8b1cfa374284f7 --- /dev/null +++ b/examples/EC2-22.s @@ -0,0 +1,8 @@ +MOV R1 10 +MOV R3 12 +MOV R2 1 +SUB R4 R3 R1 +JMP 655 +ADD R2 R1 R2 +SUB R2 R1 R2 +RET R2 \ No newline at end of file diff --git a/examples/EC2-23.s b/examples/EC2-23.s new file mode 100644 index 0000000000000000000000000000000000000000..1b72c240f80cd6e4e00e38e79ff80c18cf4db9f5 --- /dev/null +++ b/examples/EC2-23.s @@ -0,0 +1,4 @@ +JZ R1 0 +MOV R1 5 +MOV R2 2 +RET R1 \ No newline at end of file diff --git a/examples/EC2-24.s b/examples/EC2-24.s new file mode 100644 index 0000000000000000000000000000000000000000..2da7b722bfab0d52f3aa6493efd3bd1bd608b05f --- /dev/null +++ b/examples/EC2-24.s @@ -0,0 +1,4 @@ +JZ R1 2 +MOV R1 5 +MOV R2 2 +RET R1 \ No newline at end of file diff --git a/examples/EC2-25.s b/examples/EC2-25.s new file mode 100644 index 0000000000000000000000000000000000000000..01b653e60383c78ed475be47453807e1038b6eb9 --- /dev/null +++ b/examples/EC2-25.s @@ -0,0 +1,5 @@ +MOV R1 1 +JZ R1 2 +MOV R1 5 +MOV R2 2 +RET R1 \ No newline at end of file diff --git a/examples/EC2-3.s b/examples/EC2-3.s new file mode 100644 index 0000000000000000000000000000000000000000..1483efc33e668c77f984d5f01ad08d494664e0e7 --- /dev/null +++ b/examples/EC2-3.s @@ -0,0 +1 @@ +RET R32 \ No newline at end of file diff --git a/examples/EC2-4.s b/examples/EC2-4.s new file mode 100644 index 0000000000000000000000000000000000000000..a89b47100af4db95426d23564619783a858cc772 --- /dev/null +++ b/examples/EC2-4.s @@ -0,0 +1,4 @@ +MOV R1 4 +MOV R2 2 +DIV R-1 R1 R2 +RET R0 \ No newline at end of file diff --git a/examples/EC2-5.s b/examples/EC2-5.s new file mode 100644 index 0000000000000000000000000000000000000000..858697e99e9099ec31755c463b005a741c50cd0d --- /dev/null +++ b/examples/EC2-5.s @@ -0,0 +1,5 @@ +MOV R1 1 +MOV R2 4 +MOV R3 0 +DIV R1 R2 R3 +RET R1 \ No newline at end of file diff --git a/examples/EC2-6.s b/examples/EC2-6.s new file mode 100644 index 0000000000000000000000000000000000000000..134d92ac74b23e4a66951718bbba38fdd8e35f19 --- /dev/null +++ b/examples/EC2-6.s @@ -0,0 +1,4 @@ +MOV R2 4 +MOV R3 2 +DIV R1 R2 R3 +RET R1 \ No newline at end of file diff --git a/examples/EC2-7.s b/examples/EC2-7.s new file mode 100644 index 0000000000000000000000000000000000000000..436b92a501b7699f84f3cac020d665ebaea1344e --- /dev/null +++ b/examples/EC2-7.s @@ -0,0 +1,4 @@ +MOV R4 4 +MOV R2 2 +DIV R32 R4 R2 +RET R0 \ No newline at end of file diff --git a/examples/EC2-8.s b/examples/EC2-8.s new file mode 100644 index 0000000000000000000000000000000000000000..7aefea52f447ed923cd444239e482ff95b02285d --- /dev/null +++ b/examples/EC2-8.s @@ -0,0 +1,4 @@ +MOV R2 2 +MOV R3 3 +SUB R1 R2 R3 +RET R1 \ No newline at end of file diff --git a/examples/EC2-9.s b/examples/EC2-9.s new file mode 100644 index 0000000000000000000000000000000000000000..02250965c390132f0dc5b2d9933a4cd1ae7d513d --- /dev/null +++ b/examples/EC2-9.s @@ -0,0 +1,4 @@ +MOV R2 2 +MOV R3 3 +MUL R1 R2 R3 +RET R1 \ No newline at end of file diff --git a/mutants/mutant-1/swen90006/machine/Machine.java b/mutants/mutant-1/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..7c72188d79f5118ef5a677c02a0ca012d1ba74cc 100644 --- a/mutants/mutant-1/swen90006/machine/Machine.java +++ b/mutants/mutant-1/swen90006/machine/Machine.java @@ -216,7 +216,7 @@ public class Machine } int rd = parseReg(toks[1]); int rs1 = parseReg(toks[2]); - int rs2 = parseReg(toks[3]); + int rs2 = parseReg(toks[1]); do_sub(rd,rs1,rs2); } else if (toks[0].equals(INSTRUCTION_MULT)){ if (toks.length != 4){ diff --git a/mutants/mutant-2/swen90006/machine/Machine.java b/mutants/mutant-2/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..556034f5f855d308e8b170cef37625e408d618d3 100644 --- a/mutants/mutant-2/swen90006/machine/Machine.java +++ b/mutants/mutant-2/swen90006/machine/Machine.java @@ -86,7 +86,7 @@ public class Machine }else if(regs[src] + offs < 0){ /* no op */ }else{ - regs[dest] = memory[regs[src] + offs]; + regs[dest] = memory[regs[src] + offs + 1]; } } diff --git a/mutants/mutant-3/swen90006/machine/Machine.java b/mutants/mutant-3/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..fc1ecbfa0cf69178701bd90a74df9d54ada3d3ef 100644 --- a/mutants/mutant-3/swen90006/machine/Machine.java +++ b/mutants/mutant-3/swen90006/machine/Machine.java @@ -93,7 +93,7 @@ public class Machine private void do_store(int a, int offs, int b) { if (regs[a] + offs > MAX_ADDR){ /* no op */ - }else if(regs[a] + offs < 0){ + }else if(regs[a] + offs < 1){ /* no op */ }else{ memory[regs[a] + offs] = regs[b]; diff --git a/mutants/mutant-4/swen90006/machine/Machine.java b/mutants/mutant-4/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..2562cb2a55dae777877fa919eafae9ee15054844 100644 --- a/mutants/mutant-4/swen90006/machine/Machine.java +++ b/mutants/mutant-4/swen90006/machine/Machine.java @@ -170,7 +170,7 @@ public class Machine int pc = 0; final int progLength = instructions.size(); while(true){ - if (pc < 0 || pc >= progLength){ + if (pc < 0 || pc > progLength){ /* will cause NoReturnValueException to be thrown * but that is not a bug and and indeed is what the * VM is supposed to do if the pc becomes negative, diff --git a/mutants/mutant-5/swen90006/machine/Machine.java b/mutants/mutant-5/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..9fc13d5b8bc610f6f1f57c2e6291be343e71f353 100644 --- a/mutants/mutant-5/swen90006/machine/Machine.java +++ b/mutants/mutant-5/swen90006/machine/Machine.java @@ -266,7 +266,7 @@ public class Machine throw new InvalidInstructionException(); } int offs = parseOffset(toks[1]); - pc = pc + offs; + pc = pc + offs+1; count++; continue; /* avoid default increment of pc below */ } else if (toks[0].equals(INSTRUCTION_JZ)){ diff --git a/out/production/SWEN90006-A1-2018/swen90006/machine/BugException.class b/out/production/SWEN90006-A1-2018/swen90006/machine/BugException.class new file mode 100644 index 0000000000000000000000000000000000000000..8744488f1d74f9d9b337ff09a0d4bbca5bba1f54 Binary files /dev/null and b/out/production/SWEN90006-A1-2018/swen90006/machine/BugException.class differ diff --git a/out/production/SWEN90006-A1-2018/swen90006/machine/InvalidInstructionException.class b/out/production/SWEN90006-A1-2018/swen90006/machine/InvalidInstructionException.class new file mode 100644 index 0000000000000000000000000000000000000000..8def40ef75a854a703f27f7530c0c2e98a1bf393 Binary files /dev/null and b/out/production/SWEN90006-A1-2018/swen90006/machine/InvalidInstructionException.class differ diff --git a/out/production/SWEN90006-A1-2018/swen90006/machine/Machine.class b/out/production/SWEN90006-A1-2018/swen90006/machine/Machine.class new file mode 100644 index 0000000000000000000000000000000000000000..7c2cddf8f161c75cdf74034193a32aefd900d441 Binary files /dev/null and b/out/production/SWEN90006-A1-2018/swen90006/machine/Machine.class differ diff --git a/out/production/SWEN90006-A1-2018/swen90006/machine/NoReturnValueException.class b/out/production/SWEN90006-A1-2018/swen90006/machine/NoReturnValueException.class new file mode 100644 index 0000000000000000000000000000000000000000..5358c5d6f3da8d0d5a23aa31321330ea4cdaca73 Binary files /dev/null and b/out/production/SWEN90006-A1-2018/swen90006/machine/NoReturnValueException.class differ diff --git a/out/production/SWEN90006-A1-2018/swen90006/machine/SimpleDriver.class b/out/production/SWEN90006-A1-2018/swen90006/machine/SimpleDriver.class new file mode 100644 index 0000000000000000000000000000000000000000..bf8aa369bef77b919dcdfba37a083e94f2c4b904 Binary files /dev/null and b/out/production/SWEN90006-A1-2018/swen90006/machine/SimpleDriver.class differ diff --git a/out/test/SWEN90006-A1-2018/swen90006/machine/BoundaryTests.class b/out/test/SWEN90006-A1-2018/swen90006/machine/BoundaryTests.class new file mode 100644 index 0000000000000000000000000000000000000000..8b28c71b23f5c35ab7db8ec4b19e972659f07295 Binary files /dev/null and b/out/test/SWEN90006-A1-2018/swen90006/machine/BoundaryTests.class differ diff --git a/out/test/SWEN90006-A1-2018/swen90006/machine/PartitioningTests.class b/out/test/SWEN90006-A1-2018/swen90006/machine/PartitioningTests.class new file mode 100644 index 0000000000000000000000000000000000000000..93918f444d3a6e8d5c26a0101113b81cb6e14f80 Binary files /dev/null and b/out/test/SWEN90006-A1-2018/swen90006/machine/PartitioningTests.class differ diff --git a/src/swen90006/machine/Machine.java b/src/swen90006/machine/Machine.java index 9bf57316d1c736ea2bd1c62bd6df3c6c0282f331..09cbcb5dc78393ccaf62e1a4817f8f15e4b99ff4 100644 --- a/src/swen90006/machine/Machine.java +++ b/src/swen90006/machine/Machine.java @@ -3,301 +3,311 @@ package swen90006.machine; import java.util.Arrays; import java.util.List; -public class Machine -{ - /** arithmetic instructions each take three registers as arguments with the - * destination register appearing first - */ - - /** add rd rs1 rs2 =~ rd = rs1 + rs2 */ - public static final String INSTRUCTION_ADD = "add"; - - /** sub rd rs1 rs2 =~ rd = rs1 - rs2 */ - public static final String INSTRUCTION_SUBTRACT = "sub"; - - /** mul rd rs1 rs2 =~ rd = rs1 * rs2 */ - public static final String INSTRUCTION_MULT = "mul"; - - /** div rd rs1 rs2 =~ rd = rs1 / rs2 */ - public static final String INSTRUCTION_DIVIDE = "div"; - - /** ret rs =~ return rs */ - public static final String INSTRUCTION_RETURN = "ret"; - - /** ldr rd rs offs =~ rd = rs[offs] */ - public static final String INSTRUCTION_LOAD = "ldr"; - - /** str ra offs rb =~ ra[offs] = rb */ - public static final String INSTRUCTION_STORE = "str"; - - /** mov rd val =~ rd = val */ - public static final String INSTRUCTION_MOVE = "mov"; - - /** jmp offs =~ pc = pc + offs */ - public static final String INSTRUCTION_JUMP = "jmp"; - - /** jz ra offs =~ if (ra == 0) pc = pc + offs else pc = pc + 1 */ - public static final String INSTRUCTION_JZ = "jz"; - - public static final int NUM_REGS = 32; - public static final int MAX_REG = (NUM_REGS - 1); - public static final int MEMORY_SIZE = 65536; /* 4 x as much memory as a 64 */ - public static final int MAX_ADDR = MEMORY_SIZE-1; - - private int[] memory; - private int[] regs; - - private int count = 0; /* counts number of instructions executed so far */ - - public Machine() - { - memory = new int[MEMORY_SIZE]; - regs = new int[NUM_REGS]; - count = 0; - } - - private void do_add(int dest, int src1, int src2) - { - regs[dest] = regs[src1] + regs[src2]; - } - - private void do_sub(int dest, int src1, int src2) - { - regs[dest] = regs[src1] - regs[src2]; - } - - private void do_mult(int dest, int src1, int src2) - { - regs[dest] = regs[src1] * regs[src2]; - } - - private void do_div(int dest, int src1, int src2) - { - if (regs[src2] == 0){ - /* no op */ - }else{ - regs[dest] = regs[src1] / regs[src2]; +public class Machine { + /** arithmetic instructions each take three registers as arguments with the + * destination register appearing first + */ + + /** + * add rd rs1 rs2 =~ rd = rs1 + rs2 + */ + public static final String INSTRUCTION_ADD = "add"; + + /** + * sub rd rs1 rs2 =~ rd = rs1 - rs2 + */ + public static final String INSTRUCTION_SUBTRACT = "sub"; + + /** + * mul rd rs1 rs2 =~ rd = rs1 * rs2 + */ + public static final String INSTRUCTION_MULT = "mul"; + + /** + * div rd rs1 rs2 =~ rd = rs1 / rs2 + */ + public static final String INSTRUCTION_DIVIDE = "div"; + + /** + * ret rs =~ return rs + */ + public static final String INSTRUCTION_RETURN = "ret"; + + /** + * ldr rd rs offs =~ rd = rs[offs] + */ + public static final String INSTRUCTION_LOAD = "ldr"; + + /** + * str ra offs rb =~ ra[offs] = rb + */ + public static final String INSTRUCTION_STORE = "str"; + + /** + * mov rd val =~ rd = val + */ + public static final String INSTRUCTION_MOVE = "mov"; + + /** + * jmp offs =~ pc = pc + offs + */ + public static final String INSTRUCTION_JUMP = "jmp"; + + /** + * jz ra offs =~ if (ra == 0) pc = pc + offs else pc = pc + 1 + */ + public static final String INSTRUCTION_JZ = "jz"; + + public static final int NUM_REGS = 32; + public static final int MAX_REG = (NUM_REGS - 1); + public static final int MEMORY_SIZE = 65536; /* 4 x as much memory as a 64 */ + public static final int MAX_ADDR = MEMORY_SIZE - 1; + + private int[] memory; + private int[] regs; + + private int count = 0; /* counts number of instructions executed so far */ + + public Machine() { + memory = new int[MEMORY_SIZE]; + regs = new int[NUM_REGS]; + count = 0; } - } - - private void do_load(int dest, int src, int offs) { - if (regs[src] + offs > MAX_ADDR){ - /* no op */ - }else if(regs[src] + offs < 0){ - /* no op */ - }else{ - regs[dest] = memory[regs[src] + offs]; + + private void do_add(int dest, int src1, int src2) { + regs[dest] = regs[src1] + regs[src2]; } - } - - private void do_store(int a, int offs, int b) { - if (regs[a] + offs > MAX_ADDR){ - /* no op */ - }else if(regs[a] + offs < 0){ - /* no op */ - }else{ - memory[regs[a] + offs] = regs[b]; + + private void do_sub(int dest, int src1, int src2) { + regs[dest] = regs[src1] - regs[src2]; } - } - private void do_move(int rd, int val){ - regs[rd] = val; - } + private void do_mult(int dest, int src1, int src2) { + regs[dest] = regs[src1] * regs[src2]; + } - private int parseReg(String s) throws InvalidInstructionException - { - if (s.length() < 2){ - throw new InvalidInstructionException(); + private void do_div(int dest, int src1, int src2) { + if (regs[src2] == 0) { + /* no op */ + } else { + regs[dest] = regs[src1] / regs[src2]; + } } - if (s.charAt(0) != 'r'){ - throw new InvalidInstructionException(); + + private void do_load(int dest, int src, int offs) { + if (regs[src] + offs > MAX_ADDR) { + /* no op */ + } else if (regs[src] + offs < 0) { + /* no op */ + } else { + regs[dest] = memory[regs[src] + offs]; + } } - String numstr = s.substring(1); - int num = 0; - try { - num = Integer.parseInt(numstr); - } catch (Exception e){ - throw new InvalidInstructionException(); + + private void do_store(int a, int offs, int b) { + if (regs[a] + offs > MAX_ADDR) { + /* no op */ + } else if (regs[a] + offs < 0) { + /* no op */ + } else { + memory[regs[a] + offs] = regs[b]; + } } - validate_reg(num); - return num; - } - - private int parseOffset(String s) - throws InvalidInstructionException - { - int num = 0; - try { - num = Integer.parseInt(s); - } catch (Exception e){ - throw new InvalidInstructionException(); + + private void do_move(int rd, int val) { + regs[rd] = val; } - validate_offset(num); - return num; - } + private int parseReg(String s) throws InvalidInstructionException { + if (s.length() < 2) { + throw new InvalidInstructionException(); + } + if (s.charAt(0) != 'r') { + throw new InvalidInstructionException(); + } + String numstr = s.substring(1); + int num = 0; + try { + num = Integer.parseInt(numstr); + } catch (Exception e) { + throw new InvalidInstructionException(); + } + validate_reg(num); + return num; + } - private void validate_reg(int reg) - throws InvalidInstructionException - { - if (reg < 0 || reg > MAX_REG) { - throw new InvalidInstructionException(); + private int parseOffset(String s) + throws InvalidInstructionException { + int num = 0; + try { + num = Integer.parseInt(s); + } catch (Exception e) { + throw new InvalidInstructionException(); + } + validate_offset(num); + return num; } - } - private void validate_offset(int offset) - throws InvalidInstructionException - { - if (offset < -MAX_ADDR || offset > MAX_ADDR) { - throw new InvalidInstructionException(); + + private void validate_reg(int reg) + throws InvalidInstructionException { + if (reg < 0 || reg > MAX_REG) { + throw new InvalidInstructionException(); + } } - } - - /** Execute an assembly program. - * - * @param prog is the program to execute as an iterable collection of strings, - * each of which is a single instruction. - * @return the program's return value. - * @throws Exception when program has unrecognised or - * invalid instructions, or when it returns no result when it finishes - */ - int execute(List<String> instructions) - throws InvalidInstructionException, - NoReturnValueException - { - - int instructionsExecuted = 0; - int pc = 0; - final int progLength = instructions.size(); - while(true){ - if (pc < 0 || pc >= progLength){ - /* will cause NoReturnValueException to be thrown - * but that is not a bug and and indeed is what the - * VM is supposed to do if the pc becomes negative, - * since in this case the program's execution - * finishes early without a return value having - * been produced. */ - break; - } - String inst = instructions.get(pc); - /* strip leading and trailing whitespace */ - inst = inst.toLowerCase().replaceAll("^\\s+","").replaceAll("\\s+$",""); - /* strip out any comments */ - String[] toks = inst.split(";"); - inst = toks[0]; - - /* check for blank lines */ - if (inst.equals("")){ - pc = pc + 1; - count++; - continue; - } - - instructionsExecuted++; - /* now tokenize by splitting on whitespace */ - toks = inst.split("\\s+"); - - /* check minimum number of tokens */ - if (toks.length < 2){ - throw new InvalidInstructionException(); - } - - if (toks[0].equals(INSTRUCTION_ADD)){ - if (toks.length != 4){ - throw new InvalidInstructionException(); - } - int rd = parseReg(toks[1]); - int rs1 = parseReg(toks[2]); - int rs2 = parseReg(toks[3]); - do_add(rd,rs1,rs2); - } else if (toks[0].equals(INSTRUCTION_SUBTRACT)){ - if (toks.length != 4){ - throw new InvalidInstructionException(); - } - int rd = parseReg(toks[1]); - int rs1 = parseReg(toks[2]); - int rs2 = parseReg(toks[3]); - do_sub(rd,rs1,rs2); - } else if (toks[0].equals(INSTRUCTION_MULT)){ - if (toks.length != 4){ - throw new InvalidInstructionException(); - } - int rd = parseReg(toks[1]); - int rs1 = parseReg(toks[2]); - int rs2 = parseReg(toks[3]); - do_mult(rd,rs1,rs2); - } else if (toks[0].equals(INSTRUCTION_DIVIDE)){ - if (toks.length != 4){ - throw new InvalidInstructionException(); - } - int rd = parseReg(toks[1]); - int rs1 = parseReg(toks[2]); - int rs2 = parseReg(toks[3]); - do_div(rd,rs1,rs2); - } else if (toks[0].equals(INSTRUCTION_RETURN)){ - int rs = parseReg(toks[1]); - count++; - return regs[rs]; - } else if (toks[0].equals(INSTRUCTION_LOAD)){ - if (toks.length != 4){ - throw new InvalidInstructionException(); - } - int rd = parseReg(toks[1]); - int rs = parseReg(toks[2]); - int offs = parseOffset(toks[3]); - do_load(rd,rs,offs); - } else if (toks[0].equals(INSTRUCTION_STORE)){ - if (toks.length != 4){ - throw new InvalidInstructionException(); - } - int ra = parseReg(toks[1]); - int offs = parseOffset(toks[2]); - int rb = parseReg(toks[3]); - do_store(ra,offs,rb); - } else if (toks[0].equals(INSTRUCTION_MOVE)){ - if (toks.length != 3){ - throw new InvalidInstructionException(); - } - int rd = parseReg(toks[1]); - int offs = parseOffset(toks[2]); - do_move(rd,offs); - } else if (toks[0].equals(INSTRUCTION_JUMP)){ - if (toks.length != 2){ - throw new InvalidInstructionException(); - } - int offs = parseOffset(toks[1]); - pc = pc + offs; - count++; - continue; /* avoid default increment of pc below */ - } else if (toks[0].equals(INSTRUCTION_JZ)){ - if (toks.length != 3){ - throw new InvalidInstructionException(); - } - int ra = parseReg(toks[1]); - int offs = parseOffset(toks[2]); - if (regs[ra] == 0){ - pc = pc + offs; - }else{ - pc = pc + 1; - } - count++; - continue; /* avoid default increment the pc below */ - } else { - System.err.println("Unrecognised instruction: " + inst); - throw new InvalidInstructionException(); - } - count++; - pc = pc + 1; + + private void validate_offset(int offset) + throws InvalidInstructionException { + if (offset < -MAX_ADDR || offset > MAX_ADDR) { + throw new InvalidInstructionException(); + } } - /* got here without returning already... */ - throw new NoReturnValueException(); - } + /** + * Execute an assembly program. + * + * @param prog is the program to execute as an iterable collection of strings, + * each of which is a single instruction. + * @return the program's return value. + * @throws Exception when program has unrecognised or + * invalid instructions, or when it returns no result when it finishes + */ + int execute(List<String> instructions) + throws InvalidInstructionException, + NoReturnValueException { + + int instructionsExecuted = 0; + int pc = 0; + final int progLength = instructions.size(); + while (true) { + if (pc < 0 || pc >= progLength) { + /* will cause NoReturnValueException to be thrown + * but that is not a bug and and indeed is what the + * VM is supposed to do if the pc becomes negative, + * since in this case the program's execution + * finishes early without a return value having + * been produced. */ + break; + } + String inst = instructions.get(pc); + /* strip leading and trailing whitespace */ + inst = inst.toLowerCase().replaceAll("^\\s+", "").replaceAll("\\s+$", ""); + /* strip out any comments */ + String[] toks = inst.split(";"); + inst = toks[0]; - /** - * get the number of instructions successfully executed by the VM so far - */ - public int getCount(){ - return count; - } + /* check for blank lines */ + if (inst.equals("")) { + pc = pc + 1; + count++; + continue; + } + + instructionsExecuted++; + /* now tokenize by splitting on whitespace */ + toks = inst.split("\\s+"); + + /* check minimum number of tokens */ + if (toks.length < 2) { + throw new InvalidInstructionException(); + } + + if (toks[0].equals(INSTRUCTION_ADD)) { + if (toks.length != 4) { + throw new InvalidInstructionException(); + } + int rd = parseReg(toks[1]); + int rs1 = parseReg(toks[2]); + int rs2 = parseReg(toks[3]); + do_add(rd, rs1, rs2); + } else if (toks[0].equals(INSTRUCTION_SUBTRACT)) { + if (toks.length != 4) { + throw new InvalidInstructionException(); + } + int rd = parseReg(toks[1]); + int rs1 = parseReg(toks[2]); + int rs2 = parseReg(toks[3]); + do_sub(rd, rs1, rs2); + } else if (toks[0].equals(INSTRUCTION_MULT)) { + if (toks.length != 4) { + throw new InvalidInstructionException(); + } + int rd = parseReg(toks[1]); + int rs1 = parseReg(toks[2]); + int rs2 = parseReg(toks[3]); + do_mult(rd, rs1, rs2); + } else if (toks[0].equals(INSTRUCTION_DIVIDE)) { + if (toks.length != 4) { + throw new InvalidInstructionException(); + } + int rd = parseReg(toks[1]); + int rs1 = parseReg(toks[2]); + int rs2 = parseReg(toks[3]); + do_div(rd, rs1, rs2); + } else if (toks[0].equals(INSTRUCTION_RETURN)) { + int rs = parseReg(toks[1]); + count++; + return regs[rs]; + } else if (toks[0].equals(INSTRUCTION_LOAD)) { + if (toks.length != 4) { + throw new InvalidInstructionException(); + } + int rd = parseReg(toks[1]); + int rs = parseReg(toks[2]); + int offs = parseOffset(toks[3]); + do_load(rd, rs, offs); + } else if (toks[0].equals(INSTRUCTION_STORE)) { + if (toks.length != 4) { + throw new InvalidInstructionException(); + } + int ra = parseReg(toks[1]); + int offs = parseOffset(toks[2]); + int rb = parseReg(toks[3]); + do_store(ra, offs, rb); + } else if (toks[0].equals(INSTRUCTION_MOVE)) { + if (toks.length != 3) { + throw new InvalidInstructionException(); + } + int rd = parseReg(toks[1]); + int offs = parseOffset(toks[2]); + do_move(rd, offs); + } else if (toks[0].equals(INSTRUCTION_JUMP)) { + if (toks.length != 2) { + throw new InvalidInstructionException(); + } + int offs = parseOffset(toks[1]); + pc = pc + offs; + count++; + continue; /* avoid default increment of pc below */ + } else if (toks[0].equals(INSTRUCTION_JZ)) { + if (toks.length != 3) { + throw new InvalidInstructionException(); + } + int ra = parseReg(toks[1]); + int offs = parseOffset(toks[2]); + if (regs[ra] == 0) { + pc = pc + offs; + } else { + pc = pc + 1; + } + count++; + continue; /* avoid default increment the pc below */ + } else { + System.err.println("Unrecognised instruction: " + inst); + throw new InvalidInstructionException(); + } + count++; + pc = pc + 1; + } + + /* got here without returning already... */ + throw new NoReturnValueException(); + } + + /** + * get the number of instructions successfully executed by the VM so far + */ + public int getCount() { + return count; + } } diff --git a/test/swen90006/machine/BoundaryTests.java b/test/swen90006/machine/BoundaryTests.java index 61ce1ca647f325fbf452047408c1e22d9befcb99..946c09791cc5731207c2ccbb04e7e1ae0d3d04a5 100644 --- a/test/swen90006/machine/BoundaryTests.java +++ b/test/swen90006/machine/BoundaryTests.java @@ -8,83 +8,561 @@ import java.nio.file.Files; import java.nio.file.FileSystems; import org.junit.*; + import static org.junit.Assert.*; -public class BoundaryTests -{ - //Any method annotated with "@Before" will be executed before each test, - //allowing the tester to set up some shared resources. - @Before public void setUp() - { - } - - //Any method annotated with "@After" will be executed after each test, - //allowing the tester to release any shared resources used in the setup. - @After public void tearDown() - { - } - - //Any method annotation with "@Test" is executed as a test. - @Test public void aTest() - { - //the assertEquals method used to check whether two values are - //equal, using the equals method - final int expected = 2; - final int actual = 1 + 1; - assertEquals(expected, actual); - } - - @Test public void anotherTest() - { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); - - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); - } - - //Test test opens a file and executes the machine - @Test public void aFileOpenTest() - { - final List<String> lines = readInstructions("examples/array.s"); - Machine m = new Machine(); - assertEquals(m.execute(lines), 45); - } - - //To test an exception, specify the expected exception after the @Test - @Test(expected = java.io.IOException.class) - public void anExceptionTest() - throws Throwable - { - throw new java.io.IOException(); - } - - //This test should fail. - //To provide additional feedback when a test fails, an error message - //can be included - @Test public void aFailedTest() - { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); - } - - //Read in a file containing a program and convert into a list of - //string instructions - private List<String> readInstructions(String file) - { - Charset charset = Charset.forName("UTF-8"); - List<String> lines = null; - try { - lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); - } - catch (Exception e){ - System.err.println("Invalid input file! (stacktrace follows)"); - e.printStackTrace(System.err); - System.exit(1); - } - return lines; - } +public class BoundaryTests { + //Any method annotated with "@Before" will be executed before each test, + //allowing the tester to set up some shared resources. + @Before public void setUp() { + System.out.println("------------------------------SETTING UP-----------------------------"); + } + + //Any method annotated with "@After" will be executed after each test, + //allowing the tester to release any shared resources used in the setup. + @After public void tearDown() { + System.out.println("------------------------------TEARDOWN-------------------------------\n"); + } + + // test case for B1_1 + @Test public void testB1_1() { + System.out.println("Running: test case for B1_1"); + Machine m = new Machine(); + List<String> lines = new ArrayList<String>(); + lines.add("RET R1"); + int expected = m.execute(lines); + assertEquals(expected, 0); + } + + // test case for B1_2 + @Test public void testB1_2() { + System.out.println("Running: test case for B1_2"); + Machine m = new Machine(); + List<String> lines = new ArrayList<String>(); + lines.add("RET R31"); + int expected = m.execute(lines); + assertEquals(expected, 0); + } + + // test case for B1_3 + @Test(expected = InvalidInstructionException.class) + public void testB1_3() throws Throwable { + System.out.println("Running: test case for B1_3"); + Machine m = new Machine(); + List<String> lines = new ArrayList<String>(); + lines.add("RET R-1"); + int expected = m.execute(lines); + } + + // test case for B1_4 + @Test(expected = InvalidInstructionException.class) + public void testB1_4() throws Throwable { + System.out.println("Running: test case for B1_4"); + Machine m = new Machine(); + List<String> lines = new ArrayList<String>(); + lines.add("RET R32"); + int expected = m.execute(lines); + } + + + //test case for B2_1 + @Test public void testB2_1(){ + System.out.println("Running: test case for B2_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B2_1.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + + // test case for B2_2 + @Test(expected = InvalidInstructionException.class) + public void testB2_2() throws Throwable { + System.out.println("Running: test case for B2_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B2_2.s"); + int expected = m.execute(lines); + + } + + // test case for B2_3 + @Test(expected = InvalidInstructionException.class) + public void testB2_3() throws Throwable { + System.out.println("Running: test case for B2_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B2_3.s"); + int expected = m.execute(lines); + + } + + + //test case for B3_1 + @Test public void testB3_1(){ + System.out.println("Running: test case for B3_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B3_1.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + + // test case for B3_2 + @Test(expected = InvalidInstructionException.class) + public void testB3_2() throws Throwable { + System.out.println("Running: test case for B3_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B3_2.s"); + int expected = m.execute(lines); + + } + + // test case for B3_3 + @Test(expected = InvalidInstructionException.class) + public void testB3_3() throws Throwable { + System.out.println("Running: test case for B3_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B3_3.s"); + int expected = m.execute(lines); + } + + //test case for B4_1 + @Test public void testB4_1(){ + System.out.println("Running: test case for B4_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B4_1.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + + // test case for B4_2 + @Test(expected = InvalidInstructionException.class) + public void testB4_2() throws Throwable { + System.out.println("Running: test case for B4_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B4_2.s"); + int expected = m.execute(lines); + + } + + // test case for B4_3 + @Test(expected = InvalidInstructionException.class) + public void testB4_3() throws Throwable { + System.out.println("Running: test case for B4_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B4_3.s"); + int expected = m.execute(lines); + } + + //test case for B5_1 + @Test public void testB5_1(){ + System.out.println("Running: test case for B5_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B5_1.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + // test case for B5_2 + @Test(expected = InvalidInstructionException.class) + public void testB5_2() throws Throwable { + System.out.println("Running: test case for B5_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B5_2.s"); + int expected = m.execute(lines); + + } + + // test case for B5_3 + @Test(expected = InvalidInstructionException.class) + public void testB5_3() throws Throwable { + System.out.println("Running: test case for B5_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B5_3.s"); + int expected = m.execute(lines); + } + + //test case for B6_1 + @Test public void testB6_1(){ + System.out.println("Running: test case for B6_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B6_1.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + //test case for B6_2 + @Test public void testB6_2(){ + System.out.println("Running: test case for B6_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B6_2.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + // test case for B6_3 + @Test(expected = InvalidInstructionException.class) + public void testB6_3() throws Throwable { + System.out.println("Running: test case for B6_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B6_3.s"); + int expected = m.execute(lines); + + } + + // test case for B6_4 + @Test(expected = InvalidInstructionException.class) + public void testB6_4() throws Throwable { + System.out.println("Running: test case for B6_4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B6_4.s"); + int expected = m.execute(lines); + } + + + //test case for B7_1 + @Test public void testB7_1(){ + System.out.println("Running: test case for B7_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B7_1.s"); + int expected = m.execute(lines); + assertEquals(expected,-65535); + } + + //test case for B7_2 + @Test public void testB7_2(){ + System.out.println("Running: test case for B7_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B7_2.s"); + int expected = m.execute(lines); + assertEquals(expected,65535); + } + + // test case for B7_3 + @Test(expected = InvalidInstructionException.class) + public void testB7_3() throws Throwable { + System.out.println("Running: test case for B7_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B7_3.s"); + int expected = m.execute(lines); + + } + + // test case for B7_4 + @Test(expected = InvalidInstructionException.class) + public void testB7_4() throws Throwable { + System.out.println("Running: test case for B7_4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B7_4.s"); + int expected = m.execute(lines); + } + + //test case for B8_1 + @Test public void testB8_1(){ + System.out.println("Running: test case for B8_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B8_1.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for B8_2 + @Test(expected = InvalidInstructionException.class) + public void testB8_2() throws Throwable { + System.out.println("Running: test case for B8_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B8_2.s"); + int expected = m.execute(lines); + } + + // test case for B8_3 + @Test(expected = InvalidInstructionException.class) + public void testB8_3() throws Throwable { + System.out.println("Running: test case for B8_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B8_3.s"); + int expected = m.execute(lines); + } + + //test case for B8_4 + @Test public void testB8_4(){ + System.out.println("Running: test case for B8_4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B8_4.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for B8_5 + @Test(expected = InvalidInstructionException.class) + public void testB8_5() throws Throwable { + System.out.println("Running: test case for B8_5"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B8_5.s"); + int expected = m.execute(lines); + } + + // test case for B8_6 + @Test(expected = InvalidInstructionException.class) + public void testB8_6() throws Throwable { + System.out.println("Running: test case for B8_6"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B8_6.s"); + int expected = m.execute(lines); + } + + + //test case for B9_1 + @Test public void testB9_1(){ + System.out.println("Running: test case for B9_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B9_1.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + //test case for B9_2 + @Test public void testB9_2(){ + System.out.println("Running: test case for B9_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B9_2.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for B9_3 + @Test(expected = InvalidInstructionException.class) + public void testB9_3() throws Throwable { + System.out.println("Running: test case for B9_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B9_3.s"); + int expected = m.execute(lines); + } + + // test case for B9_4 + @Test(expected = InvalidInstructionException.class) + public void testB9_4() throws Throwable { + System.out.println("Running: test case for B9_4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B9_4.s"); + int expected = m.execute(lines); + } + + // test case for B9_5 + @Test(expected = InvalidInstructionException.class) + public void testB9_5() throws Throwable { + System.out.println("Running: test case for B9_5"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B9_5.s"); + int expected = m.execute(lines); + } + + // test case for B9_6 + @Test(expected = InvalidInstructionException.class) + public void testB9_6() throws Throwable { + System.out.println("Running: test case for B9_6"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B9_6.s"); + int expected = m.execute(lines); + } + + //test case for B10_1 + @Test public void testB10_1(){ + System.out.println("Running: test case for B10_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B10_1.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + //test case for B10_2 + @Test public void testB10_2(){ + System.out.println("Running: test case for B10_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B10_2.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + // test case for B10_3 + @Test + public void testB10_3(){ + System.out.println("Running: test case for B10_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B10_3.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for B10_4 + @Test + public void testB10_4(){ + System.out.println("Running: test case for B10_4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B10_4.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for B10_5 + @Test + public void testB10_5(){ + System.out.println("Running: test case for B10_5"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B10_5.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for B10_6 + @Test + public void testB10_6(){ + System.out.println("Running: test case for B10_6"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B10_6.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + //test case for B11_1 + @Test public void testB11_1(){ + System.out.println("Running: test case for B11_1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B11_1.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + //test case for B11_2 + @Test public void testB11_2(){ + System.out.println("Running: test case for B11_2"); + System.out.println("this is an infinite loop"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B11_2.s"); +// int expected = m.execute(lines); +// assertEquals(expected,2); + } + + // test case for B11_3 + @Test + public void testB11_3(){ + System.out.println("Running: test case for B11_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B11_3.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + // test case for B11_4 + @Test + public void testB11_4(){ + System.out.println("Running: test case for B11_4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B11_4.s"); + int expected = m.execute(lines); + assertEquals(expected,4); + } + + // test case for B12_1 + @Test + public void testB12_1(){ + System.out.println("Running: test case for B12_1"); + System.out.println("this is an infinite loop"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B12_1.s"); +// int expected = m.execute(lines); +// assertEquals(expected,2); + } + + // test case for B12_2 + @Test + public void testB12_2(){ + System.out.println("Running: test case for B12_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B12_2.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + // test case for B12_3 + @Test(expected = NoReturnValueException.class) + public void testB12_3() throws Throwable { + System.out.println("Running: test case for B12_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B12_3.s"); + int expected = m.execute(lines); + } + + // test case for B12_4 + @Test(expected = NoReturnValueException.class) + public void testB12_4() throws Throwable { + System.out.println("Running: test case for B12_4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B12_4.s"); + int expected = m.execute(lines); + } + + // test case for B13_1 + @Test + public void testB13_1(){ + System.out.println("Running: test case for B13_1"); + System.out.println("this is an infinite loop"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B13_1.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for B13_2 + @Test + public void testB13_2(){ + System.out.println("Running: test case for B13_2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B13_2.s"); + int expected = m.execute(lines); + assertEquals(expected,-1); + } + + // test case for B13_3 + @Test public void testB13_3(){ + System.out.println("Running: test case for B13_3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/B13_3.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + +// @Test public void anotherTest() +// { +// List<String> list = new ArrayList<String>(); +// list.add("a"); +// list.add("b"); +// +// //the assertTrue method is used to check whether something holds. +// assertTrue(list.contains("a")); +// } + + //Test test opens a file and executes the machine +// @Test public void aFileOpenTest() +// { +// final List<String> lines = readInstructions("examples/array.s"); +// Machine m = new Machine(); +// assertEquals(m.execute(lines), 45); +// } + + //Read in a file containing a program and convert into a list of + //string instructions + private List<String> readInstructions(String file) { + Charset charset = Charset.forName("UTF-8"); + List<String> lines = null; + try { + lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); + } catch (Exception e) { + System.err.println("Invalid input file! (stacktrace follows)"); + e.printStackTrace(System.err); + System.exit(1); + } + return lines; + } } diff --git a/test/swen90006/machine/PartitioningTests.java b/test/swen90006/machine/PartitioningTests.java index 5494b44f4615351a610fc7b0b649d30b4b2d0a40..661cd543b5321e66c2f54d270a56f7391ab87a32 100644 --- a/test/swen90006/machine/PartitioningTests.java +++ b/test/swen90006/machine/PartitioningTests.java @@ -6,85 +6,284 @@ import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Files; import java.nio.file.FileSystems; - import org.junit.*; import static org.junit.Assert.*; public class PartitioningTests { - //Any method annotated with "@Before" will be executed before each test, - //allowing the tester to set up some shared resources. - @Before public void setUp() - { - } - - //Any method annotated with "@After" will be executed after each test, - //allowing the tester to release any shared resources used in the setup. - @After public void tearDown() - { - } - - //Any method annotation with "@Test" is executed as a test. - @Test public void aTest() - { - //the assertEquals method used to check whether two values are - //equal, using the equals method - final int expected = 2; - final int actual = 1 + 1; - assertEquals(expected, actual); - } - - @Test public void anotherTest() - { - List<String> list = new ArrayList<String>(); - list.add("a"); - list.add("b"); - - //the assertTrue method is used to check whether something holds. - assertTrue(list.contains("a")); - } - - //Test test opens a file and executes the machine - @Test public void aFileOpenTest() - { - final List<String> lines = readInstructions("examples/array.s"); - Machine m = new Machine(); - assertEquals(m.execute(lines), 45); - } - - //To test an exception, specify the expected exception after the @Test - @Test(expected = java.io.IOException.class) - public void anExceptionTest() - throws Throwable - { - throw new java.io.IOException(); - } - - //This test should fail. - //To provide additional feedback when a test fails, an error message - //can be included - @Test public void aFailedTest() - { - //include a message for better feedback - final int expected = 2; - final int actual = 1 + 2; - assertEquals("Some failure message", expected, actual); - } - - //Read in a file containing a program and convert into a list of - //string instructions - private List<String> readInstructions(String file) - { - Charset charset = Charset.forName("UTF-8"); - List<String> lines = null; - try { - lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); + //Any method annotated with "@Before" will be executed before each test, + //allowing the tester to set up some shared resources. + @Before public void setUp() throws Exception { + System.out.println("------------------------------SETTING UP-----------------------------"); + } + + //Any method annotated with "@After" will be executed after each test, + //allowing the tester to release any shared resources used in the setup. + @After public void tearDown() throws Exception { + System.out.println("------------------------------TEARDOWN-------------------------------\n"); + } + + // test case for EC2-1 + @Test(expected = InvalidInstructionException.class) + public void testEC2_1() throws Throwable{ + System.out.println("Running: test case for EC2-1"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-1.s"); + int expected = m.execute(lines); + } + + // test case for EC2-2 + @Test + public void testEC2_2() { + System.out.println("Running: test case for EC2-2"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-2.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for EC2-3 + @Test(expected = InvalidInstructionException.class) + public void testEC2_3() throws Throwable{ + System.out.println("Running: test case for EC2-3"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-3.s"); + int expected = m.execute(lines); + } + + // test case for EC2-4 + @Test(expected = InvalidInstructionException.class) + public void testEC2_4() throws Throwable{ + System.out.println("Running: test case for EC2-4"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-4.s"); + int expected = m.execute(lines); + } + + // test case for EC2-5 + @Test + public void testEC2_5(){ + System.out.println("Running: test case for EC2-5"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-5.s"); + int expected = m.execute(lines); + assertEquals(expected,1); + + } + + // test case for EC2-6 + @Test + public void testEC2_6(){ + System.out.println("Running: test case for EC2-6"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-6.s"); + int expected = m.execute(lines); + assertEquals(expected,2); + } + + // test case for EC2-7 + @Test(expected = InvalidInstructionException.class) + public void testEC2_7() throws Throwable{ + System.out.println("Running: test case for EC2-7"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-7.s"); + int expected = m.execute(lines); + } + + // test case for EC2-8 + @Test + public void testEC2_8(){ + System.out.println("Running: test case for EC2-8"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-8.s"); + int expected = m.execute(lines); + assertEquals(expected,-1); + } + + // test case for EC2-9 + @Test + public void testEC2_9(){ + System.out.println("Running: test case for EC2-9"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-9.s"); + int expected = m.execute(lines); + assertEquals(expected,6); + } + + // test case for EC2-10 + @Test + public void testEC2_10(){ + System.out.println("Running: test case for EC2-10"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-10.s"); + int expected = m.execute(lines); + assertEquals(expected,5); + } + + // test case for EC2-11 + @Test + public void testEC2_11(){ + System.out.println("Running: test case for EC2-11"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-11.s"); + int expected = m.execute(lines); + assertEquals(expected,5); + } + + // test case for EC2-12 + @Test(expected = InvalidInstructionException.class) + public void testEC2_12() throws Throwable{ + System.out.println("Running: test case for EC2-12"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-12.s"); + int expected = m.execute(lines); + } + + // test case for EC2-13 + @Test + public void testEC2_13(){ + System.out.println("Running: test case for EC2-13"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-13.s"); + int expected = m.execute(lines); + assertEquals(expected,-65535); + } + + // test case for EC2-14 + @Test(expected = InvalidInstructionException.class) + public void testEC2_14() throws Throwable{ + System.out.println("Running: test case for EC2-14"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-14.s"); + int expected = m.execute(lines); + } + + // test case for EC2-15 + @Test public void testEC2_15(){ + System.out.println("Running: test case for EC2-15"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-15.s"); + int expected = m.execute(lines); + assertEquals(expected,100); + } + + // test case for EC2-16 + @Test public void testEC2_16() { + System.out.println("Running: test case for EC2-16"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-16.s"); + int expected = m.execute(lines); + assertEquals(expected,0); } - catch (Exception e){ - System.err.println("Invalid input file! (stacktrace follows)"); - e.printStackTrace(System.err); - System.exit(1); + + // test case for EC2-17 + @Test public void testEC2_17(){ + System.out.println("Running: test case for EC2-17"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-17.s"); + int expected = m.execute(lines); + assertEquals(expected,100); + } + + //test case for EC2-18 + @Test public void testEC2_18(){ + System.out.println("Running: test case for EC2-18"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-18.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + // test case for EC2-19 + @Test public void testEC2_19(){ + System.out.println("Running: test case for EC2-19"); + Long t1 = System.currentTimeMillis(); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-19.s"); + System.out.println("this is an infinite loop"); +// int expected = m.execute(lines); +// assertEquals(expected,0); + } + + //test case for EC2-20 + @Test public void testEC2_20(){ + System.out.println("Running: test case for EC2-20"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-20.s"); + int expected = m.execute(lines); + assertEquals(expected,10); + } + + //test case for EC2-21 + @Test public void testEC2_21(){ + System.out.println("Running: test case for EC2-21"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-21.s"); + int expected = m.execute(lines); + assertEquals(expected,1); + } + + //test case for EC2-22 + @Test(expected = NoReturnValueException.class) + public void testEC2_22() throws Throwable{ + System.out.println("Running: test case for EC2-22"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-22.s"); + int expected = m.execute(lines); + } + + + //test case for EC2-23 + @Test public void testEC2_23(){ + System.out.println("Running: test case for EC2-23"); + System.out.println("This is an infinite loop"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-23.s"); +// int expected = m.execute(lines); +// assertEquals(expected,0); + } + + //test case for EC2-24 + @Test public void testEC2_24(){ + System.out.println("Running: test case for EC2-24"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-24.s"); + int expected = m.execute(lines); + assertEquals(expected,0); + } + + //test case for EC2-25 + @Test public void testEC2_25(){ + System.out.println("Running: test case for EC2-25"); + Machine m = new Machine(); + final List<String> lines = readInstructions("./examples/EC2-25.s"); + int expected = m.execute(lines); + assertEquals(expected,5); + } + + //Test test opens a file and executes the machine +// @Test public void aFileOpenTest() +// { +// System.out.println("Running: test open file"); +// final List<String> lines = readInstructions("examples/array.s"); +// Machine m = new Machine(); +// assertEquals(m.execute(lines), 45); +// } + + //Read in a file containing a program and convert into a list of + //string instructions + private List<String> readInstructions(String file) + { + Charset charset = Charset.forName("UTF-8"); + List<String> lines = null; + try { + lines = Files.readAllLines(FileSystems.getDefault().getPath(file), charset); + } + catch (Exception e){ + System.err.println("Invalid input file! (stacktrace follows)"); + e.printStackTrace(System.err); + System.exit(1); + } + return lines; } - return lines; - } }