198 lines
3.8 KiB
C
198 lines
3.8 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "formats.c"
|
|
|
|
r* rFormat;
|
|
i* iFormat;
|
|
|
|
void initFunctions() {
|
|
rFormat = (r*)malloc(sizeof(r));
|
|
iFormat = (i*)malloc(sizeof(i));
|
|
|
|
rFormat->opcode = 0;
|
|
iFormat->opcode = 0;
|
|
}
|
|
|
|
// -------------------------- R FORMAT INSTRUCTIONS -------------------------- //
|
|
char * add(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 32;
|
|
|
|
// Unused in add instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * addu(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 33;
|
|
|
|
// Unused in addu instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * and(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 36;
|
|
|
|
// Unused in and instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * jr(int * args[]) {
|
|
rFormat->rs = *args[0];
|
|
rFormat->funct = 8;
|
|
|
|
// Unused in jr instruction.
|
|
rFormat->shamt = 0;
|
|
rFormat->rd = 0;
|
|
rFormat->rt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * nor(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 39;
|
|
|
|
// Unused in nor instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * or(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 37;
|
|
|
|
// Unused in or instruction.
|
|
rFormat->shamt = 0;
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * slt(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 42;
|
|
|
|
// Unused in slt instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * sltu(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 43;
|
|
|
|
// Unused in sltu instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * sll(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rt = *args[1];
|
|
rFormat->shamt = *args[2];
|
|
rFormat->funct = 0;
|
|
|
|
// Unused in sll instruction.
|
|
rFormat->rs = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * srl(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rt = *args[1];
|
|
rFormat->shamt = *args[2];
|
|
rFormat->funct = 2;
|
|
|
|
// Unused in sll instruction.
|
|
rFormat->rs = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * sub(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 34;
|
|
|
|
// Unused in sll instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
char * subu(int * args[]) {
|
|
rFormat->rd = *args[0];
|
|
rFormat->rs = *args[1];
|
|
rFormat->rt = *args[2];
|
|
rFormat->funct = 35;
|
|
|
|
// Unused in sll instruction.
|
|
rFormat->shamt = 0;
|
|
|
|
return rToHex(rFormat);
|
|
}
|
|
|
|
// -------------------------- I FORMAT INSTRUCTIONS -------------------------- //
|
|
char * addi(int * args[]) {
|
|
iFormat->opcode = 8;
|
|
iFormat->rt = *args[0];
|
|
iFormat->rs = *args[1];
|
|
iFormat->immediate = *args[2];
|
|
|
|
return iToHex(iFormat);
|
|
}
|
|
|
|
char * addiu(int * args[]) {
|
|
iFormat->opcode = 9;
|
|
iFormat->rt = *args[0];
|
|
iFormat->rs = *args[1];
|
|
iFormat->immediate = *args[2];
|
|
|
|
return iToHex(iFormat);
|
|
}
|
|
|
|
char * andi(int * args[]) {
|
|
iFormat->opcode = 12;
|
|
iFormat->rt = *args[0];
|
|
iFormat->rs = *args[1];
|
|
iFormat->immediate = *args[2];
|
|
|
|
return iToHex(iFormat);
|
|
}
|
|
|
|
char * beq(int * args[]) {
|
|
iFormat->opcode = 4;
|
|
iFormat->rt = *args[0];
|
|
iFormat->rs = *args[1];
|
|
iFormat->immediate = *args[2];
|
|
|
|
return iToHex(iFormat);
|
|
}
|
|
|
|
// -------------------------- J FORMAT INSTRUCTIONS -------------------------- //
|