Add new function find_data() to separate the instruction from op_code.

This commit is contained in:
lux 2017-08-07 20:59:17 +02:00
parent 683349d210
commit 1bdbf7a7e7
4 changed files with 32 additions and 3 deletions

View File

@ -1,7 +1,6 @@
#ifndef DEBUG_H #ifndef DEBUG_H
#define DEBUG_H #define DEBUG_H
#include <stdbool.h>
#include "../toy.h" #include "../toy.h"
void fprintBits(size_t const size, void const * const ptr, FILE *file_pointer); void fprintBits(size_t const size, void const * const ptr, FILE *file_pointer);

View File

@ -4,9 +4,28 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint16_t ram[RAM_SIZE]; uint16_t ram[RAM_SIZE];
uint16_t ir;
uint8_t op_code;
uint16_t pc = 0;
uint16_t accu = 0;
int data_addr=0;
bool run = true;
if(initialise_ram(ram,argc,argv)==-1) return 1; if(initialise_ram(ram,argc,argv)==-1) return 1;
makeHexDump(true,ram); // makeHexDump(true,ram);
// while(run && pc<(RAM_SIZE-1))
// {
ir = ram[2];
pc++;
op_code = get_opcode(ir);
printf("OP Code: %u\n",op_code);
data_addr=find_data(ir);
printf("Adresse: %d\n",data_addr);
// }
return 0; return 0;
} }

View File

@ -58,3 +58,12 @@ uint8_t get_opcode(uint16_t instruction)
return opcode; return opcode;
} }
int find_data(uint16_t instruction)
{
int instr;
if(instruction > 32767) instr = -1;
else instr=instruction & 4095;
return instr;
}

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#define RAM_SIZE 4096 #define RAM_SIZE 4096
@ -11,5 +12,6 @@
int initialise_ram(uint16_t *ram, int argc, char **argv ); int initialise_ram(uint16_t *ram, int argc, char **argv );
uint8_t get_opcode(uint16_t instruction); uint8_t get_opcode(uint16_t instruction);
int find_data(uint16_t instruction);
#endif #endif