0001 0x0000 0x3000 .ORIG 0x3000 0002 0x3000 0xe497 LEA R2,BUFSTART ; Get the starting point for the text buffer. 0003 0x3001 0xe02e LEA R0,PROMPT 0004 0x3002 0xf022 PUTS 0x22 ; Ask the user for a palindrome. 0005 0x3003 0xf020 INPUTLOOP GETC 0x20 ; Get a character from the user. 0006 0x3004 0xf021 OUT 0x21 ; Just echo the user input. 0007 0x3005 0x1836 ADD R4,R0,#-10 ; See if the char is a newline. 0008 0x3006 0x040a BRZ DONEINPUT ; If so, you are done with input. 0009 0x3007 0x7080 STR R0,R2,#0 ; Store the character into the buffer. 0010 0x3008 0x14a1 ADD R2,R2,#1 ; Increment the buffer pointer. 0011 0x3009 0x0e03 BRNZP INPUTLOOP ; Go back and get some more characters. 0012 0x300a 0xea97 DONEINPUT LEA R5,BUFSTART ; Check to make sure the user provided input. 0013 0x300b 0x9b40 NOT R5,R5 ; Negate BUFSTART (flip bits). 0014 0x300c 0x1b61 ADD R5,R5,#1 ; Add 1 0015 0x300d 0x1a85 ADD R5,R2,R5 ; Compare the current pointer to BUFSTART 0016 0x300e 0x042b BRZ NOINPUT ; No input was provided, exit. 0017 0x300f 0x5b60 AND R5,R5,#0 ; Clear R5. 0018 0x3010 0x7a80 STR R5,R2,#0 ; Put a null for the last character (useful for printing as string later). 0019 0x3011 0x16bf ADD R3,R2,#-1 ; R3 points to the last character that was input. 0020 0x3012 0xe497 LEA R2,BUFSTART ; R2 now points to the first character that was input. 0021 0x3013 0x6880 COMPARE LDR R4,R2,#0 ; Get the character R2 is pointing to. 0022 0x3014 0x6ac0 LDR R5,R3,#0 ; Get the character R3 is pointing to. 0023 0x3015 0x9900 NOT R4,R4 ; Need to check for equality, so flip bits. 0024 0x3016 0x1921 ADD R4,R4,#1 ; Add a 1 (finish the negation). 0025 0x3017 0x1905 ADD R4,R4,R5 ; Subtract to see if characters are equal. 0026 0x3018 0x0a21 BRNP NOTAPAL ; Not a palindrome, so print message and end. 0027 0x3019 0x18a0 ADD R4,R2,#0 ; Get the value of R3 so you can negate it. 0028 0x301a 0x9900 NOT R4,R4 ; Flip those bits. 0029 0x301b 0x1921 ADD R4,R4,#1 ; Add a 1 (finish the negation). 0030 0x301c 0x1903 ADD R4,R4,R3 ; See if you are done by computing R3 - R2. 0031 0x301d 0x0c26 BRZN ISPAL ; You are done if you get zero (pointing at same char) or a negative (past each other). 0032 0x301e 0x14a1 ADD R2,R2,#1 ; Move the R2 pointer down one character. 0033 0x301f 0x16ff ADD R3,R3,#-1 ; Move the R3 pointer up one character. 0034 0x3020 0x0e13 BRNZP COMPARE ; Now compare the next pair of characters. 0035 0x3021 0xe097 NOTAPAL LEA R0,BUFSTART ; Print out the user input. 0036 0x3022 0xf022 PUTS 0x22 0037 0x3023 0xe053 LEA R0,NOTPALSTRING 0038 0x3024 0xf022 PUTS 0x22 ; Just print that it is not a palindrome. 0039 0x3025 0xf025 HALT 0x25 ; Now just halt. 0040 0x3026 0xe097 ISPAL LEA R0,BUFSTART ; Print out the user input. 0041 0x3027 0xf022 PUTS 0x22 0042 0x3028 0xe06a LEA R0,ISPALSTRING 0043 0x3029 0xf022 PUTS 0x22 ; Just print that it is a palindrome. 0044 0x302a 0xf025 HALT 0x25 ; Now just halt. 0045 0x302b 0xe07d NOINPUT LEA R0,NOINPUTSTRING ; Print a message about getting no input. 0046 0x302c 0xf022 PUTS 0x22 0047 0x302d 0xf025 HALT 0x25 0048 0049 0x302e 0x000a PROMPT .STRINGZ "\nInput a palindrome and hit " 0050 0x302f 0x0049 0051 0x3030 0x006e 0052 0x3031 0x0070 0053 0x3032 0x0075 0054 0x3033 0x0074 0055 0x3034 0x0020 0056 0x3035 0x0061 0057 0x3036 0x0020 0058 0x3037 0x0070 0059 0x3038 0x0061 0060 0x3039 0x006c 0061 0x303a 0x0069 0062 0x303b 0x006e 0063 0x303c 0x0064 0064 0x303d 0x0072 0065 0x303e 0x006f 0066 0x303f 0x006d 0067 0x3040 0x0065 0068 0x3041 0x0020 0069 0x3042 0x0061 0070 0x3043 0x006e 0071 0x3044 0x0064 0072 0x3045 0x0020 0073 0x3046 0x0068 0074 0x3047 0x0069 0075 0x3048 0x0074 0076 0x3049 0x0020 0077 0x304a 0x003c 0078 0x304b 0x0045 0079 0x304c 0x004e 0080 0x304d 0x0054 0081 0x304e 0x0045 0082 0x304f 0x0052 0083 0x3050 0x003e 0084 0x3051 0x0020 0085 0x3052 0x0000 0086 0x3053 0x0020 NOTPALSTRING .STRINGZ " is not a palindrome.\n" 0087 0x3054 0x0069 0088 0x3055 0x0073 0089 0x3056 0x0020 0090 0x3057 0x006e 0091 0x3058 0x006f 0092 0x3059 0x0074 0093 0x305a 0x0020 0094 0x305b 0x0061 0095 0x305c 0x0020 0096 0x305d 0x0070 0097 0x305e 0x0061 0098 0x305f 0x006c 0099 0x3060 0x0069 0100 0x3061 0x006e 0101 0x3062 0x0064 0102 0x3063 0x0072 0103 0x3064 0x006f 0104 0x3065 0x006d 0105 0x3066 0x0065 0106 0x3067 0x002e 0107 0x3068 0x000a 0108 0x3069 0x0000 0109 0x306a 0x0020 ISPALSTRING .STRINGZ " is a palindrome.\n" 0110 0x306b 0x0069 0111 0x306c 0x0073 0112 0x306d 0x0020 0113 0x306e 0x0061 0114 0x306f 0x0020 0115 0x3070 0x0070 0116 0x3071 0x0061 0117 0x3072 0x006c 0118 0x3073 0x0069 0119 0x3074 0x006e 0120 0x3075 0x0064 0121 0x3076 0x0072 0122 0x3077 0x006f 0123 0x3078 0x006d 0124 0x3079 0x0065 0125 0x307a 0x002e 0126 0x307b 0x000a 0127 0x307c 0x0000 0128 0x307d 0x004e NOINPUTSTRING .STRINGZ "No input string provided." 0129 0x307e 0x006f 0130 0x307f 0x0020 0131 0x3080 0x0069 0132 0x3081 0x006e 0133 0x3082 0x0070 0134 0x3083 0x0075 0135 0x3084 0x0074 0136 0x3085 0x0020 0137 0x3086 0x0073 0138 0x3087 0x0074 0139 0x3088 0x0072 0140 0x3089 0x0069 0141 0x308a 0x006e 0142 0x308b 0x0067 0143 0x308c 0x0020 0144 0x308d 0x0070 0145 0x308e 0x0072 0146 0x308f 0x006f 0147 0x3090 0x0076 0148 0x3091 0x0069 0149 0x3092 0x0064 0150 0x3093 0x0065 0151 0x3094 0x0064 0152 0x3095 0x002e 0153 0x3096 0x0000 0154 0x3097 0x0000 BUFSTART .BLKW 30 0155 0x3098 0x0000 0156 0x3099 0x0000 0157 0x309a 0x0000 0158 0x309b 0x0000 0159 0x309c 0x0000 0160 0x309d 0x0000 0161 0x309e 0x0000 0162 0x309f 0x0000 0163 0x30a0 0x0000 0164 0x30a1 0x0000 0165 0x30a2 0x0000 0166 0x30a3 0x0000 0167 0x30a4 0x0000 0168 0x30a5 0x0000 0169 0x30a6 0x0000 0170 0x30a7 0x0000 0171 0x30a8 0x0000 0172 0x30a9 0x0000 0173 0x30aa 0x0000 0174 0x30ab 0x0000 0175 0x30ac 0x0000 0176 0x30ad 0x0000 0177 0x30ae 0x0000 0178 0x30af 0x0000 0179 0x30b0 0x0000 0180 0x30b1 0x0000 0181 0x30b2 0x0000 0182 0x30b3 0x0000 0183 0x30b4 0x0000 0184 0185