LODI, LODR, STRI, STRR

This commit is contained in:
Giulio De Pasquale 2017-05-24 15:29:20 +02:00
parent 0dfd9bdb57
commit 97dc35863b
4 changed files with 58 additions and 19 deletions

View File

@ -6,7 +6,8 @@
void encrypt(uint32_t *v, uint32_t *k) {
uint32_t v0 = v[0], v1 = v[1], sum = 0, i; /* set up */
uint32_t delta = 0x9e3779b9; /* a key schedule constant */
//uint32_t delta = 0x9e3779b9; /* a key schedule constant */
uint16_t delta= 0x9e37;
uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; /* cache key */
for (i = 0; i < 32; i++) { /* basic cycle start */
sum += delta;

View File

@ -4,8 +4,10 @@ MEMORY LOCATIONS AND IMMEDIATES ARE 16 BITS LONG
enum OPS_STARTING_VALUES {
MOVI,
MOVR,
LOAD,
STOR,
LODI,
LODR,
STRI,
STRR,
ADDI,
ADDR,
SUBI,
@ -67,8 +69,10 @@ INSTRUCTION SIZES
*/
#define MOVI_SIZE IMM2REG
#define MOVR_SIZE REG2REG
#define LOAD_SIZE IMM2REG
#define STOR_SIZE REG2IMM
#define LODI_SIZE IMM2REG
#define LODR_SIZE REG2REG
#define STRI_SIZE IMM2REG
#define STRR_SIZE REG2REG
#define ADDI_SIZE IMM2REG
#define ADDR_SIZE REG2REG
#define SUBI_SIZE IMM2REG

View File

@ -201,32 +201,58 @@ bool VM::execMOVR(void) {
return true;
}
bool VM::execLOAD(void) {
bool VM::execLODI(void) {
/*
LOAD R0, 0x1000 -> R0 = data[0x1000]
LODI R0, 0x1000 -> R0 = data[0x1000]
*/
uint8_t dst;
uint16_t src;
dst = as.code[regs[IP] + 1];
src = *((uint16_t *)&as.code[regs[IP] + 2]);
DBG_INFO(("LOAD %s, 0x%x\n", getRegName(dst), src));
DBG_INFO(("LODI %s, 0x%x\n", getRegName(dst), src));
regs[dst] = *((uint16_t *)&as.data[src]);
return true;
}
bool VM::execSTOR(void) {
bool VM::execLODR(void) {
/*
STOR 0x1000, R0 -> data[0x1000] = R0
LODR R1, R0 -> R1 = data[R0]
*/
uint16_t dst;
uint8_t src;
dst = as.code[regs[IP] + 1] >> 4;
src = as.code[regs[IP] + 1] & 0b00001111;
DBG_INFO(("LODR %s, %s\n", getRegName(dst), getRegName(src)));
regs[dst] = *((uint16_t *)&as.data[regs[src]]);
return true;
}
bool VM::execSTRI(void) {
/*
STRI 0x1000, R0 -> data[0x1000] = R0
*/
uint16_t dst;
uint8_t src;
dst = *((uint16_t *)&as.code[regs[IP] + 1]);
src = as.code[regs[IP] + 3];
DBG_INFO(("STOR 0x%x, %s\n", dst, getRegName(src)));
DBG_INFO(("STRI 0x%x, %s\n", dst, getRegName(src)));
*((uint16_t *)&as.data[dst]) = regs[src];
return true;
}
bool VM::execSTRR(void) {
/*
STRR R1, R0 -> data[R1] = R0
*/
uint8_t dst;
uint8_t src;
dst = as.code[regs[IP] + 1] >> 4;
src = as.code[regs[IP] + 1] & 0b00001111;
DBG_INFO(("STRR %s, %s\n", getRegName(dst), getRegName(src)));
*((uint16_t *)&as.data[regs[dst]]) = regs[src];
return true;
}
bool VM::execADDI(void) {
/*
ADDI R0, 0x2 -> R0 += 2
@ -750,12 +776,18 @@ void VM::run(void) {
} else if (opcode == OPS[MOVR]) {
execMOVR();
regs[IP] += MOVR_SIZE;
} else if (opcode == OPS[LOAD]) {
execLOAD();
regs[IP] += LOAD_SIZE;
} else if (opcode == OPS[STOR]) {
execSTOR();
regs[IP] += STOR_SIZE;
} else if (opcode == OPS[LODI]) {
execLODI();
regs[IP] += LODI_SIZE;
} else if (opcode == OPS[LODR]) {
execLODR();
regs[IP] += LODR_SIZE;
} else if (opcode == OPS[STRI]) {
execSTRI();
regs[IP] += STRI_SIZE;
} else if (opcode == OPS[STRR]) {
execSTRR();
regs[IP] += STRR_SIZE;
} else if (opcode == OPS[ADDI]) {
execADDI();
regs[IP] += ADDI_SIZE;

View File

@ -34,8 +34,10 @@ private:
bool execMOVI(void);
bool execMOVR(void);
bool execMOVM(void);
bool execLOAD(void);
bool execSTOR(void);
bool execLODI(void);
bool execLODR(void);
bool execSTRI(void);
bool execSTRR(void);
bool execADDI(void);
bool execADDR(void);
bool execSUBI(void);