Commit eb33736430b2dd7e88d953983c611c1402619498

Authored by Imanol-Mikel Barba Sabariego
1 parent 225162b5

Implemented on-the-fly register interpretation

... ... @@ -118,6 +118,7 @@ void query()
118 118 fprintf(stderr,"Loaded state as %s",filename);
119 119 break;
120 120 case 'w':
  121 + //FIXME ALREADY
121 122 sscanf(input,"w %d %d\n",&reg,&value);
122 123 fprintf(stderr,"Setting register %d to %d",reg,value);
123 124 regs[reg] = value;
... ... @@ -152,72 +153,107 @@ uint16_t fetch_debug()
152 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 193 switch(opcode)
158 194 {
159 195 case HALT:
160 196 fprintf(stderr,"HALT\n");
161 197 break;
162 198 case MOV:
163   - fprintf(stderr,"MOV %d %d\n",arg1,arg2);
  199 + fprintf(stderr,"MOV %s %s\n",arg1,arg2);
164 200 break;
165 201 case PUSH:
166   - fprintf(stderr,"PUSH %d\n",arg1);
  202 + fprintf(stderr,"PUSH %s\n",arg1);
167 203 break;
168 204 case POP:
169   - fprintf(stderr,"POP %d\n",arg1);
  205 + fprintf(stderr,"POP %s\n",arg1);
170 206 break;
171 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 209 break;
174 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 212 break;
177 213 case JMP:
178   - fprintf(stderr,"JMP %d\n",arg1);
  214 + fprintf(stderr,"JMP %s\n",arg1);
179 215 break;
180 216 case JNZ:
181   - fprintf(stderr,"JNZ %d %d\n",arg1,arg2);
  217 + fprintf(stderr,"JNZ %s %s\n",arg1,arg2);
182 218 break;
183 219 case JZ:
184   - fprintf(stderr,"JZ %d %d\n",arg1,arg2);
  220 + fprintf(stderr,"JZ %s %s\n",arg1,arg2);
185 221 break;
186 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 224 break;
189 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 227 break;
192 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 230 break;
195 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 233 break;
198 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 236 break;
201 237 case NOT:
202   - fprintf(stderr,"NOT %d %d\n",arg1,arg2);
  238 + fprintf(stderr,"NOT %s %s\n",arg1,arg2);
203 239 break;
204 240 case LOAD:
205   - fprintf(stderr,"LOAD %d %d\n",arg1,arg2);
  241 + fprintf(stderr,"LOAD %s %s\n",arg1,arg2);
206 242 break;
207 243 case STOR:
208   - fprintf(stderr,"STOR %d %d\n",arg1,arg2);
  244 + fprintf(stderr,"STOR %s %s\n",arg1,arg2);
209 245 break;
210 246 case CALL:
211   - fprintf(stderr,"CALL %d\n",arg1);
  247 + fprintf(stderr,"CALL %s\n",arg1);
212 248 break;
213 249 case RET:
214 250 fprintf(stderr,"RET\n");
215 251 break;
216 252 case OUT:
217   - fprintf(stderr,"OUT %d\n",arg1);
  253 + fprintf(stderr,"OUT %s\n",arg1);
218 254 break;
219 255 case IN:
220   - fprintf(stderr,"IN %d\n",arg1);
  256 + fprintf(stderr,"IN %s\n",arg1);
221 257 break;
222 258 case NOP:
223 259 fprintf(stderr,"NOP\n");
... ...
disasm.c
... ... @@ -11,7 +11,7 @@ void disassemble_program(uint32_t length)
11 11 {
12 12 break;
13 13 }
14   - printf("%d: ",pc);
  14 + fprintf(stderr,"%d: ",pc);
15 15 uint16_t opcode = fetch();
16 16 decode_instruction(opcode,&arg1,&arg2,&arg3);
17 17 print_instruction(opcode,arg1,arg2,arg3);
... ...
... ... @@ -29,6 +29,7 @@ void startvm(char *program)
29 29  
30 30 void disasm(char *program)
31 31 {
  32 + stderr = stdout;
32 33 disassemble_program(load_program(program));
33 34 }
34 35  
... ...
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"