Commit eb33736430b2dd7e88d953983c611c1402619498
1 parent
225162b5
Implemented on-the-fly register interpretation
Showing
4 changed files
with
58 additions
and
33 deletions
debug.c
@@ -118,6 +118,7 @@ void query() | @@ -118,6 +118,7 @@ void query() | ||
118 | fprintf(stderr,"Loaded state as %s",filename); | 118 | fprintf(stderr,"Loaded state as %s",filename); |
119 | break; | 119 | break; |
120 | case 'w': | 120 | case 'w': |
121 | + //FIXME ALREADY | ||
121 | sscanf(input,"w %d %d\n",®,&value); | 122 | sscanf(input,"w %d %d\n",®,&value); |
122 | fprintf(stderr,"Setting register %d to %d",reg,value); | 123 | fprintf(stderr,"Setting register %d to %d",reg,value); |
123 | regs[reg] = value; | 124 | regs[reg] = value; |
@@ -152,72 +153,107 @@ uint16_t fetch_debug() | @@ -152,72 +153,107 @@ uint16_t fetch_debug() | ||
152 | return value; | 153 | return value; |
153 | } | 154 | } |
154 | 155 | ||
155 | -void print_instruction(uint16_t opcode, uint16_t arg1, uint16_t arg2, uint16_t arg3) | 156 | +void translate_args(uint16_t a1, uint16_t a2, uint16_t a3, char *arg1, char *arg2, char *arg3) |
156 | { | 157 | { |
158 | + if(a1 > MAX_INT) | ||
159 | + { | ||
160 | + sprintf(arg1,"r%d",a1-(MAX_INT+1)); | ||
161 | + } | ||
162 | + else | ||
163 | + { | ||
164 | + sprintf(arg1,"%d",a1); | ||
165 | + } | ||
166 | + | ||
167 | + if(a2 > MAX_INT) | ||
168 | + { | ||
169 | + sprintf(arg2,"r%d",a2-(MAX_INT+1)); | ||
170 | + } | ||
171 | + else | ||
172 | + { | ||
173 | + sprintf(arg2,"%d",a2); | ||
174 | + } | ||
175 | + | ||
176 | + if(a3 > MAX_INT) | ||
177 | + { | ||
178 | + sprintf(arg3,"r%d",a3-(MAX_INT+1)); | ||
179 | + } | ||
180 | + else | ||
181 | + { | ||
182 | + sprintf(arg3,"%d",a3); | ||
183 | + } | ||
184 | + | ||
185 | +} | ||
186 | + | ||
187 | +void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) | ||
188 | +{ | ||
189 | + char arg1[10]; | ||
190 | + char arg2[10]; | ||
191 | + char arg3[10]; | ||
192 | + translate_args(a1,a2,a3,arg1,arg2,arg3); | ||
157 | switch(opcode) | 193 | switch(opcode) |
158 | { | 194 | { |
159 | case HALT: | 195 | case HALT: |
160 | fprintf(stderr,"HALT\n"); | 196 | fprintf(stderr,"HALT\n"); |
161 | break; | 197 | break; |
162 | case MOV: | 198 | case MOV: |
163 | - fprintf(stderr,"MOV %d %d\n",arg1,arg2); | 199 | + fprintf(stderr,"MOV %s %s\n",arg1,arg2); |
164 | break; | 200 | break; |
165 | case PUSH: | 201 | case PUSH: |
166 | - fprintf(stderr,"PUSH %d\n",arg1); | 202 | + fprintf(stderr,"PUSH %s\n",arg1); |
167 | break; | 203 | break; |
168 | case POP: | 204 | case POP: |
169 | - fprintf(stderr,"POP %d\n",arg1); | 205 | + fprintf(stderr,"POP %s\n",arg1); |
170 | break; | 206 | break; |
171 | case TEQ: | 207 | case TEQ: |
172 | - fprintf(stderr,"TEQ %d %d %d\n",arg1,arg2,arg3); | 208 | + fprintf(stderr,"TEQ %s %s %s\n",arg1,arg2,arg3); |
173 | break; | 209 | break; |
174 | case TGT: | 210 | case TGT: |
175 | - fprintf(stderr,"TGT %d %d %d\n",arg1,arg2,arg3); | 211 | + fprintf(stderr,"TGT %s %s %s\n",arg1,arg2,arg3); |
176 | break; | 212 | break; |
177 | case JMP: | 213 | case JMP: |
178 | - fprintf(stderr,"JMP %d\n",arg1); | 214 | + fprintf(stderr,"JMP %s\n",arg1); |
179 | break; | 215 | break; |
180 | case JNZ: | 216 | case JNZ: |
181 | - fprintf(stderr,"JNZ %d %d\n",arg1,arg2); | 217 | + fprintf(stderr,"JNZ %s %s\n",arg1,arg2); |
182 | break; | 218 | break; |
183 | case JZ: | 219 | case JZ: |
184 | - fprintf(stderr,"JZ %d %d\n",arg1,arg2); | 220 | + fprintf(stderr,"JZ %s %s\n",arg1,arg2); |
185 | break; | 221 | break; |
186 | case ADD: | 222 | case ADD: |
187 | - fprintf(stderr,"ADD %d %d %d\n",arg1,arg2,arg3); | 223 | + fprintf(stderr,"ADD %s %s %s\n",arg1,arg2,arg3); |
188 | break; | 224 | break; |
189 | case MUL: | 225 | case MUL: |
190 | - fprintf(stderr,"MUL %d %d %d\n",arg1,arg2,arg3); | 226 | + fprintf(stderr,"MUL %s %s %s\n",arg1,arg2,arg3); |
191 | break; | 227 | break; |
192 | case MOD: | 228 | case MOD: |
193 | - fprintf(stderr,"MOD %d %d %d\n",arg1,arg2,arg3); | 229 | + fprintf(stderr,"MOD %s %s %s\n",arg1,arg2,arg3); |
194 | break; | 230 | break; |
195 | case AND: | 231 | case AND: |
196 | - fprintf(stderr,"AND %d %d %d\n",arg1,arg2,arg3); | 232 | + fprintf(stderr,"AND %s %s %s\n",arg1,arg2,arg3); |
197 | break; | 233 | break; |
198 | case OR: | 234 | case OR: |
199 | - fprintf(stderr,"OR %d %d %d\n",arg1,arg2,arg3); | 235 | + fprintf(stderr,"OR %s %s %s\n",arg1,arg2,arg3); |
200 | break; | 236 | break; |
201 | case NOT: | 237 | case NOT: |
202 | - fprintf(stderr,"NOT %d %d\n",arg1,arg2); | 238 | + fprintf(stderr,"NOT %s %s\n",arg1,arg2); |
203 | break; | 239 | break; |
204 | case LOAD: | 240 | case LOAD: |
205 | - fprintf(stderr,"LOAD %d %d\n",arg1,arg2); | 241 | + fprintf(stderr,"LOAD %s %s\n",arg1,arg2); |
206 | break; | 242 | break; |
207 | case STOR: | 243 | case STOR: |
208 | - fprintf(stderr,"STOR %d %d\n",arg1,arg2); | 244 | + fprintf(stderr,"STOR %s %s\n",arg1,arg2); |
209 | break; | 245 | break; |
210 | case CALL: | 246 | case CALL: |
211 | - fprintf(stderr,"CALL %d\n",arg1); | 247 | + fprintf(stderr,"CALL %s\n",arg1); |
212 | break; | 248 | break; |
213 | case RET: | 249 | case RET: |
214 | fprintf(stderr,"RET\n"); | 250 | fprintf(stderr,"RET\n"); |
215 | break; | 251 | break; |
216 | case OUT: | 252 | case OUT: |
217 | - fprintf(stderr,"OUT %d\n",arg1); | 253 | + fprintf(stderr,"OUT %s\n",arg1); |
218 | break; | 254 | break; |
219 | case IN: | 255 | case IN: |
220 | - fprintf(stderr,"IN %d\n",arg1); | 256 | + fprintf(stderr,"IN %s\n",arg1); |
221 | break; | 257 | break; |
222 | case NOP: | 258 | case NOP: |
223 | fprintf(stderr,"NOP\n"); | 259 | fprintf(stderr,"NOP\n"); |
disasm.c
@@ -11,7 +11,7 @@ void disassemble_program(uint32_t length) | @@ -11,7 +11,7 @@ void disassemble_program(uint32_t length) | ||
11 | { | 11 | { |
12 | break; | 12 | break; |
13 | } | 13 | } |
14 | - printf("%d: ",pc); | 14 | + fprintf(stderr,"%d: ",pc); |
15 | uint16_t opcode = fetch(); | 15 | uint16_t opcode = fetch(); |
16 | decode_instruction(opcode,&arg1,&arg2,&arg3); | 16 | decode_instruction(opcode,&arg1,&arg2,&arg3); |
17 | print_instruction(opcode,arg1,arg2,arg3); | 17 | print_instruction(opcode,arg1,arg2,arg3); |
main.c
scripts/process_disasm.sh deleted
1 | -#!/bin/bash | ||
2 | - | ||
3 | -PROGRAM="$1" | ||
4 | - | ||
5 | -sed -i "s/32768/r0/g" "$PROGRAM" | ||
6 | -sed -i "s/32769/r1/g" "$PROGRAM" | ||
7 | -sed -i "s/32770/r2/g" "$PROGRAM" | ||
8 | -sed -i "s/32771/r3/g" "$PROGRAM" | ||
9 | -sed -i "s/32772/r4/g" "$PROGRAM" | ||
10 | -sed -i "s/32773/r5/g" "$PROGRAM" | ||
11 | -sed -i "s/32774/r6/g" "$PROGRAM" | ||
12 | -sed -i "s/32775/r7/g" "$PROGRAM" |