0001 0x0000 0x3000 .ORIG 0X3000 0002 ;; Read the first binary number. 0003 0x3000 0xe04b LEA R0,PROMPT1 ; This is the first string. 0004 0x3001 0xf022 PUTS 0x22 ; This prints out the prompt. 0005 0x3002 0x4827 JSR READINPUT ; Read the first string. 0006 0x3003 0x354e ST R2,A ; Put the result into A 0007 0x3004 0xe07a LEA R0,PROMPT2 ; This is the second string. 0008 0x3005 0xf022 PUTS 0x22 ; This prints out the prompt. 0009 0x3006 0x4827 JSR READINPUT ; Read the second string. 0010 0x3007 0x354f ST R2,B ; Put the result into B 0011 0012 0x3008 0x274e LD R3,A 0013 0x3009 0x294f LD R4,B 0014 0x300a 0x5ac4 AND R5,R3,R4 ; AND them together. 0015 0x300b 0xe0a9 LEA R0,MSG1 ; Get the first message. 0016 0x300c 0xf022 PUTS 0x22 ; Print the message. 0017 0x300d 0x1360 ADD R1,R5,#0 ; Move the value into R1. 0018 0x300e 0x483b JSR WRITEOUTPUT ; Write the result. 0019 0020 0x300f 0x274e LD R3,A 0021 0x3010 0x294f LD R4,B 0022 0x3011 0x9ac0 NOT R5,R3 ; Compute the NOT of R3 0023 0x3012 0x9d00 NOT R6,R4 ; Compute the NOT of R4 0024 0x3013 0x5f46 AND R7,R5,R6 ; Compute the AND of NOT(R3), NOT(R4) 0025 0x3014 0x93c0 NOT R1,R7 ; Compute the NOT(AND(NOT(R3),NOT(R4))) 0026 0x3015 0xe0d8 LEA R0,MSG2 ; Get the next message. 0027 0x3016 0xf022 PUTS 0x22 ; Print the message. 0028 0x3017 0x483b JSR WRITEOUTPUT 0029 0030 0x3018 0xe108 LEA R0,MSG3 0031 0x3019 0xf022 PUTS 0x22 0032 0x301a 0x234e LD R1,A ; Get A 0033 0x301b 0x254f LD R2,B ; Get B 0034 0x301c 0x9640 NOT R3,R1 ; NOT A 0035 0x301d 0x9880 NOT R4,R2 ; NOT B 0036 0x301e 0x5ac2 AND R5,R3,R2 ; AND(NOT(A), B) 0037 0x301f 0x9b40 NOT R5,R5 ; NOT(AND(NOT(A), B)) 0038 0x3020 0x5c44 AND R6,R1,R4 ; AND(A, NOT(B)) 0039 0x3021 0x9d80 NOT R6,R6 ; NOT(AND(A, NOT(B))) 0040 0x3022 0x5f46 AND R7,R5,R6 ; AND(NOT(AND(A, NOT(B))), NOT(AND(NOT(A), B))) 0041 0x3023 0x9fc0 NOT R7,R7 ; NOT all of that^ 0042 0x3024 0x13e0 ADD R1,R7,#0 0043 0x3025 0x483b JSR WRITEOUTPUT 0044 0x3026 0xf025 HALT 0x25 0045 0046 ;; Read input into R2. 0047 0x3027 0x3f52 READINPUT ST R7,SAVER7 ; Save the return address. 0048 0x3028 0x54a0 AND R2,R2,#0 ; Clear out the result register. 0049 0x3029 0xf020 INPUTLOOP GETC 0x20 ; Get a character from the user. 0050 0x302a 0xf021 OUT 0x21 ; Echo the input. 0051 0x302b 0x234b LD R1,ONEN ; Get the negated ASCII value for zero. 0052 0x302c 0x1201 ADD R1,R0,R1 ; Check to see if you got a ONE. 0053 0x302d 0x0a31 BRNP NOTAONE ; Skip the shift if not a ONE. 0054 0x302e 0x1482 ADD R2,R2,R2 ; Shift to the left for the next digit. 0055 0x302f 0x14a1 ADD R2,R2,#1 ; Add a one because it was a ONE. 0056 0x3030 0x0e29 BRNZP INPUTLOOP ; Go get another character. 0057 0x3031 0x234a NOTAONE LD R1,ZERON ; Get the negated ASCII value for one. 0058 0x3032 0x1201 ADD R1,R0,R1 ; Check to see if you got a ZERO. 0059 0x3033 0x0a36 BRNP NOTAZERO ; Take no more input if not ZERO or ONE. 0060 0x3034 0x1482 ADD R2,R2,R2 ; Shift to the left for the next digit. 0061 0x3035 0x0e29 BRNZP INPUTLOOP ; You got a ZERO, go get some more input. 0062 0x3036 0x2350 NOTAZERO LD R1,NEWLINEN ; Load the negated value for NEWLINE. 0063 0x3037 0x1201 ADD R1,R0,R1 ; Check to see if you got a NEWLINE. 0064 0x3038 0x0a48 BRNP ERROR ; You have an error if not ONE, ZERO, NEWLINE. 0065 0x3039 0x2f52 LD R7,SAVER7 ; Restore R7. 0066 0x303a 0xd000 RET 0067 0068 ;; Write the binary string from register R1. 0069 0x303b 0x3f52 WRITEOUTPUT ST R7,SAVER7 ; Save the return address. 0070 0x303c 0xe553 LEA R2,TABLE ; Get start address for bit patterns. 0071 0x303d 0x6680 OUTPUTLOOP LDR R3,R2,#0 ; Load the bit pattern from the table. 0072 0x303e 0x0846 BRN DONEOUTPUT ; If negative, you are at end of table. 0073 0x303f 0x214d LD R0,ONE ; Assume that you will write a ONE. 0074 0x3040 0x56c1 AND R3,R3,R1 ; Check to see if the bit in R1 is set. 0075 0x3041 0x0a43 BRNP WRITEONE ; Put a ONE on the output. 0076 0x3042 0x214c LD R0,ZERO ; Otherwise, overwrite the ONE with a ZERO. 0077 0x3043 0xf021 WRITEONE OUT 0x21 ; Do the actual output. 0078 0x3044 0x14a1 ADD R2,R2,#1 ; Increment the table pointer. 0079 0x3045 0x0e3d BRNZP OUTPUTLOOP ; Do the next bit. 0080 0081 DONEOUTPUT 0082 ; LD R0, NEWLINE ; Get a newline. 0083 ; OUT ; Print it. 0084 0x3046 0x2f52 LD R7,SAVER7 ; Restore R7. 0085 0x3047 0xd000 RET 0086 0087 0x3048 0xe138 ERROR LEA R0,ERRMSG ; Load the error message. 0088 0x3049 0xf022 PUTS 0x22 ; Print the prompt. 0089 0x304a 0xf025 HALT 0x25 0090 0091 0x304b 0x0049 PROMPT1 .STRINGZ "Input the first binary value and hit " 0092 0x304c 0x006e 0093 0x304d 0x0070 0094 0x304e 0x0075 0095 0x304f 0x0074 0096 0x3050 0x0020 0097 0x3051 0x0074 0098 0x3052 0x0068 0099 0x3053 0x0065 0100 0x3054 0x0020 0101 0x3055 0x0066 0102 0x3056 0x0069 0103 0x3057 0x0072 0104 0x3058 0x0073 0105 0x3059 0x0074 0106 0x305a 0x0020 0107 0x305b 0x0020 0108 0x305c 0x0062 0109 0x305d 0x0069 0110 0x305e 0x006e 0111 0x305f 0x0061 0112 0x3060 0x0072 0113 0x3061 0x0079 0114 0x3062 0x0020 0115 0x3063 0x0076 0116 0x3064 0x0061 0117 0x3065 0x006c 0118 0x3066 0x0075 0119 0x3067 0x0065 0120 0x3068 0x0020 0121 0x3069 0x0061 0122 0x306a 0x006e 0123 0x306b 0x0064 0124 0x306c 0x0020 0125 0x306d 0x0068 0126 0x306e 0x0069 0127 0x306f 0x0074 0128 0x3070 0x0020 0129 0x3071 0x003c 0130 0x3072 0x0045 0131 0x3073 0x004e 0132 0x3074 0x0054 0133 0x3075 0x0045 0134 0x3076 0x0052 0135 0x3077 0x003e 0136 0x3078 0x0020 0137 0x3079 0x0000 0138 0x307a 0x0049 PROMPT2 .STRINGZ "Input the second binary value and hit " 0139 0x307b 0x006e 0140 0x307c 0x0070 0141 0x307d 0x0075 0142 0x307e 0x0074 0143 0x307f 0x0020 0144 0x3080 0x0074 0145 0x3081 0x0068 0146 0x3082 0x0065 0147 0x3083 0x0020 0148 0x3084 0x0073 0149 0x3085 0x0065 0150 0x3086 0x0063 0151 0x3087 0x006f 0152 0x3088 0x006e 0153 0x3089 0x0064 0154 0x308a 0x0020 0155 0x308b 0x0062 0156 0x308c 0x0069 0157 0x308d 0x006e 0158 0x308e 0x0061 0159 0x308f 0x0072 0160 0x3090 0x0079 0161 0x3091 0x0020 0162 0x3092 0x0076 0163 0x3093 0x0061 0164 0x3094 0x006c 0165 0x3095 0x0075 0166 0x3096 0x0065 0167 0x3097 0x0020 0168 0x3098 0x0061 0169 0x3099 0x006e 0170 0x309a 0x0064 0171 0x309b 0x0020 0172 0x309c 0x0068 0173 0x309d 0x0069 0174 0x309e 0x0074 0175 0x309f 0x0020 0176 0x30a0 0x003c 0177 0x30a1 0x0045 0178 0x30a2 0x004e 0179 0x30a3 0x0054 0180 0x30a4 0x0045 0181 0x30a5 0x0052 0182 0x30a6 0x003e 0183 0x30a7 0x0020 0184 0x30a8 0x0000 0185 0x30a9 0x0020 MSG1 .STRINGZ " AND Result: " 0186 0x30aa 0x0020 0187 0x30ab 0x0020 0188 0x30ac 0x0020 0189 0x30ad 0x0020 0190 0x30ae 0x0020 0191 0x30af 0x0020 0192 0x30b0 0x0020 0193 0x30b1 0x0020 0194 0x30b2 0x0020 0195 0x30b3 0x0020 0196 0x30b4 0x0020 0197 0x30b5 0x0020 0198 0x30b6 0x0020 0199 0x30b7 0x0020 0200 0x30b8 0x0020 0201 0x30b9 0x0020 0202 0x30ba 0x0020 0203 0x30bb 0x0020 0204 0x30bc 0x0020 0205 0x30bd 0x0020 0206 0x30be 0x0020 0207 0x30bf 0x0020 0208 0x30c0 0x0020 0209 0x30c1 0x0020 0210 0x30c2 0x0020 0211 0x30c3 0x0020 0212 0x30c4 0x0020 0213 0x30c5 0x0020 0214 0x30c6 0x0020 0215 0x30c7 0x0020 0216 0x30c8 0x0020 0217 0x30c9 0x0020 0218 0x30ca 0x0020 0219 0x30cb 0x0041 0220 0x30cc 0x004e 0221 0x30cd 0x0044 0222 0x30ce 0x0020 0223 0x30cf 0x0052 0224 0x30d0 0x0065 0225 0x30d1 0x0073 0226 0x30d2 0x0075 0227 0x30d3 0x006c 0228 0x30d4 0x0074 0229 0x30d5 0x003a 0230 0x30d6 0x0020 0231 0x30d7 0x0000 0232 0x30d8 0x000a MSG2 .STRINGZ "\n OR Result: " 0233 0x30d9 0x0020 0234 0x30da 0x0020 0235 0x30db 0x0020 0236 0x30dc 0x0020 0237 0x30dd 0x0020 0238 0x30de 0x0020 0239 0x30df 0x0020 0240 0x30e0 0x0020 0241 0x30e1 0x0020 0242 0x30e2 0x0020 0243 0x30e3 0x0020 0244 0x30e4 0x0020 0245 0x30e5 0x0020 0246 0x30e6 0x0020 0247 0x30e7 0x0020 0248 0x30e8 0x0020 0249 0x30e9 0x0020 0250 0x30ea 0x0020 0251 0x30eb 0x0020 0252 0x30ec 0x0020 0253 0x30ed 0x0020 0254 0x30ee 0x0020 0255 0x30ef 0x0020 0256 0x30f0 0x0020 0257 0x30f1 0x0020 0258 0x30f2 0x0020 0259 0x30f3 0x0020 0260 0x30f4 0x0020 0261 0x30f5 0x0020 0262 0x30f6 0x0020 0263 0x30f7 0x0020 0264 0x30f8 0x0020 0265 0x30f9 0x0020 0266 0x30fa 0x0020 0267 0x30fb 0x004f 0268 0x30fc 0x0052 0269 0x30fd 0x0020 0270 0x30fe 0x0020 0271 0x30ff 0x0052 0272 0x3100 0x0065 0273 0x3101 0x0073 0274 0x3102 0x0075 0275 0x3103 0x006c 0276 0x3104 0x0074 0277 0x3105 0x003a 0278 0x3106 0x0020 0279 0x3107 0x0000 0280 0x3108 0x000a MSG3 .STRINGZ "\n XOR Result: " 0281 0x3109 0x0020 0282 0x310a 0x0020 0283 0x310b 0x0020 0284 0x310c 0x0020 0285 0x310d 0x0020 0286 0x310e 0x0020 0287 0x310f 0x0020 0288 0x3110 0x0020 0289 0x3111 0x0020 0290 0x3112 0x0020 0291 0x3113 0x0020 0292 0x3114 0x0020 0293 0x3115 0x0020 0294 0x3116 0x0020 0295 0x3117 0x0020 0296 0x3118 0x0020 0297 0x3119 0x0020 0298 0x311a 0x0020 0299 0x311b 0x0020 0300 0x311c 0x0020 0301 0x311d 0x0020 0302 0x311e 0x0020 0303 0x311f 0x0020 0304 0x3120 0x0020 0305 0x3121 0x0020 0306 0x3122 0x0020 0307 0x3123 0x0020 0308 0x3124 0x0020 0309 0x3125 0x0020 0310 0x3126 0x0020 0311 0x3127 0x0020 0312 0x3128 0x0020 0313 0x3129 0x0020 0314 0x312a 0x0020 0315 0x312b 0x0058 0316 0x312c 0x004f 0317 0x312d 0x0052 0318 0x312e 0x0020 0319 0x312f 0x0052 0320 0x3130 0x0065 0321 0x3131 0x0073 0322 0x3132 0x0075 0323 0x3133 0x006c 0324 0x3134 0x0074 0325 0x3135 0x003a 0326 0x3136 0x0020 0327 0x3137 0x0000 0328 0x3138 0x000a ERRMSG .STRINGZ "\nError in input!\n" 0329 0x3139 0x0045 0330 0x313a 0x0072 0331 0x313b 0x0072 0332 0x313c 0x006f 0333 0x313d 0x0072 0334 0x313e 0x0020 0335 0x313f 0x0069 0336 0x3140 0x006e 0337 0x3141 0x0020 0338 0x3142 0x0069 0339 0x3143 0x006e 0340 0x3144 0x0070 0341 0x3145 0x0075 0342 0x3146 0x0074 0343 0x3147 0x0021 0344 0x3148 0x000a 0345 0x3149 0x0000 0346 0x314a 0xffffffd0 ZERON .FILL #-48 0347 0x314b 0xffffffcf ONEN .FILL #-49 0348 0x314c 0x0030 ZERO .FILL #48 0349 0x314d 0x0031 ONE .FILL #49 0350 0351 0x314e 0x0000 A .BLKW 1 0352 0x314f 0x0000 B .BLKW 1 0353 0354 0x3150 0xfffffff6 NEWLINEN .FILL #-10 0355 0x3151 0x000a NEWLINE .FILL #10 0356 0x3152 0x0000 SAVER7 .BLKW 1 0357 0358 0x3153 0x0080 TABLE .FILL x0080 0359 0x3154 0x0040 BIT6 .FILL x0040 0360 0x3155 0x0020 BIT5 .FILL x0020 0361 0x3156 0x0010 BIT4 .FILL x0010 0362 0x3157 0x0008 BIT3 .FILL x0008 0363 0x3158 0x0004 BIT2 .FILL x0004 0364 0x3159 0x0002 BIT1 .FILL x0002 0365 0x315a 0x0001 BIT0 .FILL x0001 0366 0x315b 0xffffffff END .FILL #-1