












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













Instruction Set Simulator For A Simple
Processor
#include <stdio.h> typedef struct { unsigned char first_byte, second_byte; } instruction;
instruction program[1024]; //instruction memory unsigned char memory[256]; //data memory
void run_program(int num_bytes) {
int pc = -1; unsigned char reg[16], fb, sb;
while( ++pc < (num_bytes / 2) ) { fb = program[pc].first_byte; sb = program[pc].second_byte; switch( fb >> 4 ) { case 0: reg[fb & 0x0f] = memory[sb]; break; case 1: memory[sb] = reg[fb & 0x0f]; break; case 2: memory[reg[fb & 0x0f]] = reg[sb >> 4]; break; case 3: reg[fb & 0x0f] = sb; break; case 4: reg[fb & 0x0f] += reg[sb >> 4]; break; case 5: reg[fb & 0x0f] -= reg[sb >> 4]; break; case 6: pc += sb; break; default: return –1;
} } return 0; }
int main(int argc, char *argv[]) {
FILE* ifs;
If( argc != 2 || (ifs = fopen(argv[1], “rb”) == NULL ) { return –1; } if (run_program(fread(program, sizeof(program) == 0) { print_memory_contents(); return(0); } else return(-1); }
For example, SW0,SW1 are connected on FPGA Pins
N25,N26. LEDG0 is pin AE22.
Programming the FPGA:
Tools>Programmer
single-purpose processor