Created
May 30, 2014 04:52
-
-
Save matthew-ball/1def1fac087b6a44bf6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; --------------------------------------------------------------------- | |
; | |
; Name: Matthew Ball | |
; Student Number: 4537508 | |
; Course: COMP2300 | |
; Assignment Number: 2 | |
; Name of this file: cipher.mli | |
; Lab Group: Thursday, 8:00am - 10:00am | |
; | |
; | |
; I declare that the material I am submitting in this file is entirely | |
; my own work. I have not collaborated with anyone to produce it, nor | |
; have I copied it, in part or in full, from work produced by someone else. | |
; I have not given access to this material to any other student in this course. | |
; --------------------------------------------------------------------- | |
START a20 ; start address of the program. | |
; initialise PC to this. | |
AT a0 | |
0000 0000 0000 0000 ; a0: memory cell to store nextChar variable char nextChar; | |
0000 0000 0000 1101 ; a1: memory cell to store ROT field #define ROT 13 | |
0000 0000 0100 0000 ; a2: memory cell to store the value A-1 (64) #define A 64 | |
0000 0000 0101 1011 ; a3: memory cell to store the value Z+1 (91) #define Z 91 | |
0000 0000 0110 0000 ; a4: memory cell to store the value a-1 (96) #define a 96 | |
0000 0000 0111 1011 ; a5: memory cell to store the value z+1 (123) #define z 123 | |
0000 0000 0101 1010 ; a6: memory cell to store the value 90 | |
0000 0000 0111 1010 ; a7: memory cell to store the value 122 | |
AT a20 ; store the following instructions: | |
; main procedure | |
110101 0000 0000 10 ; a20: trap 2 (Get), read character getchar(); //Start Loop | |
001 010 a0 ; a21: store character in mem[a0] (nextChar) nextChar = mem[a0]; | |
000 111 0000 0010 10 ; a22: compare to EOL character if (nextChar == EOL) | |
101001 a36 ; a23: if equal branch to mem[a36] goto(mem[a36]); | |
; check for lower case | |
; ---------------------- | |
; check for lower bounds | |
001 111 a4 ; a24: compare AC to mem[a4] (96) if (nextChar <= mem[a4]) | |
101100 a34 ; a25: branch less/equal (if AC <= 96) skip to mem[a34] goto(mem[a34]); | |
; check for upper bounds | |
001 111 a5 ; a26: compare AC to mem[a5] (123) if (nextChar > mem[a5]) | |
101011 a44 ; a27: branch greater (if AC > 123) skip to mem[a44] goto(mem[a44]); | |
; rotate character | |
001 011 a1 ; a30: AC + mem[a1] (13) nextChar += mem[a1]; | |
001 111 a7 ; a31: compare AC to mem[a7] (122) if (AC <= 122) | |
101100 a44 ; a32: branch less/equal (if AC <= 122) skip to mem[a44] goto(mem[a44]); | |
000 100 0000 0110 10 ; a33: AC - 26 nextChar -= 26; | |
; check for upper case | |
; ---------------------- | |
; check for lower bounds | |
001 111 a2 ; a34: compare AC to mem[a2] (64) if (nextChar <= mem[a2]) | |
101100 a44 ; a35: branch less/equal (if AC <= 64) skip to mem[a44] goto(mem[a44]); | |
; check for upper bounds | |
001 111 a3 ; a36: compare AC to mem[a3] (91) if (nextChar > mem[a3]) | |
101011 a44 ; a37: branch greater (if AC > 91) skip to mem[a44] goto(mem[a44]); | |
; rotate character | |
001 011 a1 ; a40: AC + mem[a1] (13) nextChar += mem[a1]; | |
001 111 a6 ; a41: compare AC to mem[a6] (90) if (nextChar <= mem[a6]) | |
101100 a44 ; a42: branch less/equal (if AC <= 90) skip to mem[a44] goto(mem[a44]); | |
000 100 0000 0110 10 ; a43: AC - 26 nextChar -= 26; | |
110101 0000 0000 11 ; a44: trap 3 (Put), print character print(nextChar); | |
101000 a20 ; a45: jump to mem[a20], jump to start of loop goto(mem[a20]); //Repeat Loop | |
110101 0000 0000 11 ; a46: trap 3 (Put), print EOL character print(EOL); | |
110101 0000 0000 01 ; a47: trap 1 (Halt), stop the program return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment