From da69a3c18b790697408f7743b9890b0a929edbf9 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Fri, 12 Aug 2016 01:11:08 -0400 Subject: [PATCH] Incorporated Additional Push and Pop instructions --- High_level_prototypes/asm.c | 11 ++++ High_level_prototypes/disasm.c | 55 +++++++++++++++++++ ISA_HEX_Map.org | 20 ++++++- vm.h | 12 +++++ vm_decode.c | 99 ++++++++++++++++++++++++++++++++++ vm_instructions.c | 63 ++++++++++++++++++++++ 6 files changed, 259 insertions(+), 1 deletion(-) diff --git a/High_level_prototypes/asm.c b/High_level_prototypes/asm.c index c89ed46..ee07494 100644 --- a/High_level_prototypes/asm.c +++ b/High_level_prototypes/asm.c @@ -268,6 +268,17 @@ void assemble(struct Token* p) setExpression(p, "MOVE", "090005", 4); setExpression(p, "BRANCH", "090100", 4); setExpression(p, "CALL", "090101", 4); + setExpression(p, "PUSHR", "090200", 4); + setExpression(p, "PUSH8", "090201", 4); + setExpression(p, "PUSH16", "090202", 4); + setExpression(p, "PUSH32", "090203", 4); + setExpression(p, "POPR", "090280", 4); + setExpression(p, "POP8", "090281", 4); + setExpression(p, "POPU8", "090282", 4); + setExpression(p, "POP16", "090283", 4); + setExpression(p, "POPU16", "090284", 4); + setExpression(p, "POP32", "090285", 4); + setExpression(p, "POPU32", "090286", 4); /* 1OP Group */ setExpression(p, "READPC", "0D00000", 4); diff --git a/High_level_prototypes/disasm.c b/High_level_prototypes/disasm.c index 943f912..bf40955 100644 --- a/High_level_prototypes/disasm.c +++ b/High_level_prototypes/disasm.c @@ -552,6 +552,61 @@ void decode_Integer_2OP(struct Instruction* c) strncpy(Name, "CALL", 19); break; } + case 0x0200: /* PUSHR */ + { + strncpy(Name, "PUSHR", 19); + break; + } + case 0x0201: /* PUSH8 */ + { + strncpy(Name, "PUSH8", 19); + break; + } + case 0x0202: /* PUSH16 */ + { + strncpy(Name, "PUSH16", 19); + break; + } + case 0x0203: /* PUSH32 */ + { + strncpy(Name, "PUSH32", 19); + break; + } + case 0x0280: /* POPR */ + { + strncpy(Name, "POPR", 19); + break; + } + case 0x0281: /* POP8 */ + { + strncpy(Name, "POP8", 19); + break; + } + case 0x0282: /* POPU8 */ + { + strncpy(Name, "POPU8", 19); + break; + } + case 0x0283: /* POP16 */ + { + strncpy(Name, "POP16", 19); + break; + } + case 0x0284: /* POPU16 */ + { + strncpy(Name, "POPU16", 19); + break; + } + case 0x0285: /* POP32 */ + { + strncpy(Name, "POP32", 19); + break; + } + case 0x0286: /* POPU32 */ + { + strncpy(Name, "POPU32", 19); + break; + } default: /* Unknown 2OP*/ { break; diff --git a/ISA_HEX_Map.org b/ISA_HEX_Map.org index 6b6ef30..11fd8b8 100644 --- a/ISA_HEX_Map.org +++ b/ISA_HEX_Map.org @@ -218,10 +218,28 @@ | 09 01 00 ab | BRANCH a b | MEM[b] = PC; PC = a | | 09 01 01 ab | CALL a b | MEM[b] = PC; b = b + (register size in bytes); PC = a | +**** Stack group +| Hex | Name | Comment | +|-------------+------------+-----------------------------------------------------------| +| 09 02 00 ab | PUSHR a b | MEM[b] = a; b = b + (register size in bytes) | +| 09 02 01 ab | PUSH8 a b | MEM[b] = bottom_8_bits(a); b = b + 1 | +| 09 02 02 ab | PUSH16 a b | MEM[b] = bottome_16_bits(a); b = b + 2 | +| 09 02 03 ab | PUSH32 a b | MEM[b] = bottome_32_bits(a); b = b + 4 | +| 09 02 04 xx | Reserved | | +| ... | Reserved | | +| 09 02 7F xx | Reserved | | +| 09 02 80 ab | POPR a b | a = MEM[b]; MEM[b] = 0; b = b - (register size in bytes) | +| 09 02 81 ab | POP8 a b | a = MEM[b] (signed); MEM[b] = 0; b = b - 1 | +| 09 02 82 ab | POPU8 a b | a = MEM[b] (unsigned); MEM[b] = 0; b = b - 1 | +| 09 02 83 ab | POP16 a b | a = MEM[b] (signed); MEM[b] = 0; b = b - 2 | +| 09 02 84 ab | POPU16 a b | a = MEM[b] (unsigned); MEM[b] = 0; b = b - 2 | +| 09 02 85 ab | POP32 a b | a = MEM[b] (signed); MEM[b] = 0; b = b - 4 | +| 09 02 86 ab | POPU32 a b | a = MEM[b] (signed); MEM[b] = 0; b = b - 4 | + **** Reserved Block 1 | Hex | Name | |-------------+----------| -| 09 01 02 xx | Reserved | +| 09 02 87 xx | Reserved | | ... | Reserved | | 09 FF FF xx | Reserved | diff --git a/vm.h b/vm.h index 102d27f..b2031cf 100644 --- a/vm.h +++ b/vm.h @@ -203,6 +203,18 @@ void CMPSKIPU_G(struct lilith* vm, struct Instruction* c); void CMPSKIPU_GE(struct lilith* vm, struct Instruction* c); void CMPSKIPU_LE(struct lilith* vm, struct Instruction* c); void CMPSKIPU_L(struct lilith* vm, struct Instruction* c); +void PUSHR(struct lilith* vm, struct Instruction* c); +void PUSH8(struct lilith* vm, struct Instruction* c); +void PUSH16(struct lilith* vm, struct Instruction* c); +void PUSH32(struct lilith* vm, struct Instruction* c); +void POPR(struct lilith* vm, struct Instruction* c); +void POP8(struct lilith* vm, struct Instruction* c); +void POPU8(struct lilith* vm, struct Instruction* c); +void POP16(struct lilith* vm, struct Instruction* c); +void POPU16(struct lilith* vm, struct Instruction* c); +void POP32(struct lilith* vm, struct Instruction* c); +void POPU32(struct lilith* vm, struct Instruction* c); + /* Prototypes for functions in vm_decode.c*/ struct lilith* create_vm(size_t size); diff --git a/vm_decode.c b/vm_decode.c index 4200da3..22c4ac1 100644 --- a/vm_decode.c +++ b/vm_decode.c @@ -1026,6 +1026,105 @@ bool eval_2OP_Int(struct lilith* vm, struct Instruction* c) CALL(vm, c); break; } + case 0x0200: /* PUSHR */ + { + #ifdef DEBUG + strncpy(Name, "PUSHR", 19); + #endif + + PUSHR(vm, c); + break; + } + case 0x0201: /* PUSH8 */ + { + #ifdef DEBUG + strncpy(Name, "PUSH8", 19); + #endif + + PUSH8(vm, c); + break; + } + case 0x0202: /* PUSH16 */ + { + #ifdef DEBUG + strncpy(Name, "PUSH16", 19); + #endif + + PUSH16(vm, c); + break; + } + case 0x0203: /* PUSH32 */ + { + #ifdef DEBUG + strncpy(Name, "PUSH32", 19); + #endif + + PUSH32(vm, c); + break; + } + case 0x0280: /* POPR */ + { + #ifdef DEBUG + strncpy(Name, "POPR", 19); + #endif + + POPR(vm, c); + break; + } + case 0x0281: /* POP8 */ + { + #ifdef DEBUG + strncpy(Name, "POP8", 19); + #endif + + POP8(vm, c); + break; + } + case 0x0282: /* POPU8 */ + { + #ifdef DEBUG + strncpy(Name, "POPU8", 19); + #endif + + POPU8(vm, c); + break; + } + case 0x0283: /* POP16 */ + { + #ifdef DEBUG + strncpy(Name, "POP16", 19); + #endif + + POP16(vm, c); + break; + } + case 0x0284: /* POPU16 */ + { + #ifdef DEBUG + strncpy(Name, "POPU16", 19); + #endif + + POPU16(vm, c); + break; + } + case 0x0285: /* POP32 */ + { + #ifdef DEBUG + strncpy(Name, "POP32", 19); + #endif + + POP32(vm, c); + break; + } + case 0x0286: /* POPU32 */ + { + #ifdef DEBUG + strncpy(Name, "POPU32", 19); + #endif + + POPU32(vm, c); + break; + } default: return true; } #ifdef DEBUG diff --git a/vm_instructions.c b/vm_instructions.c index 64ee61f..7b7d495 100644 --- a/vm_instructions.c +++ b/vm_instructions.c @@ -1858,3 +1858,66 @@ void CMPSKIPU_L(struct lilith* vm, struct Instruction* c) vm->ip = vm->ip + 4; } } + +void PUSHR(struct lilith* vm, struct Instruction* c) +{ + writeout_Reg(vm, vm->reg[c->reg1], vm->reg[c->reg0]); + vm->reg[c->reg1] = vm->reg[c->reg1] + 4; +} +void PUSH8(struct lilith* vm, struct Instruction* c) +{ + writeout_byte(vm, vm->reg[c->reg1] , vm->reg[c->reg0]); + vm->reg[c->reg1] = vm->reg[c->reg1] + 1; +} +void PUSH16(struct lilith* vm, struct Instruction* c) +{ + writeout_doublebyte(vm, vm->reg[c->reg1] , vm->reg[c->reg0]); + vm->reg[c->reg1] = vm->reg[c->reg1] + 2; +} +void PUSH32(struct lilith* vm, struct Instruction* c) +{ + writeout_Reg(vm, vm->reg[c->reg1] , vm->reg[c->reg0]); + vm->reg[c->reg1] = vm->reg[c->reg1] + 4; +} +void POPR(struct lilith* vm, struct Instruction* c) +{ + vm->reg[c->reg1] = vm->reg[c->reg1] - 4; + vm->reg[c->reg0] = readin_Reg(vm, vm->reg[c->reg1]); + writeout_Reg(vm, vm->reg[c->reg1], 0); +} +void POP8(struct lilith* vm, struct Instruction* c) +{ + vm->reg[c->reg1] = vm->reg[c->reg1] - 1; + vm->reg[c->reg0] = readin_byte(vm, vm->reg[c->reg1], true); + writeout_byte(vm, vm->reg[c->reg1], 0); +} +void POPU8(struct lilith* vm, struct Instruction* c) +{ + vm->reg[c->reg1] = vm->reg[c->reg1] - 1; + vm->reg[c->reg0] = readin_byte(vm, vm->reg[c->reg1], false); + writeout_byte(vm, vm->reg[c->reg1], 0); +} +void POP16(struct lilith* vm, struct Instruction* c) +{ + vm->reg[c->reg1] = vm->reg[c->reg1] - 2; + vm->reg[c->reg0] = readin_doublebyte(vm, vm->reg[c->reg1], true); + writeout_doublebyte(vm, vm->reg[c->reg1], 0); +} +void POPU16(struct lilith* vm, struct Instruction* c) +{ + vm->reg[c->reg1] = vm->reg[c->reg1] - 2; + vm->reg[c->reg0] = readin_doublebyte(vm, vm->reg[c->reg1], false); + writeout_doublebyte(vm, vm->reg[c->reg1], 0); +} +void POP32(struct lilith* vm, struct Instruction* c) +{ + vm->reg[c->reg1] = vm->reg[c->reg1] - 4; + vm->reg[c->reg0] = readin_Reg(vm, vm->reg[c->reg1]); + writeout_Reg(vm, vm->reg[c->reg1], 0); +} +void POPU32(struct lilith* vm, struct Instruction* c) +{ + vm->reg[c->reg1] = vm->reg[c->reg1] - 4; + vm->reg[c->reg0] = readin_Reg(vm, vm->reg[c->reg1]); + writeout_Reg(vm, vm->reg[c->reg1], 0); +}