Stack limitato con push e pop

This commit is contained in:
Giulio De Pasquale 2017-07-08 23:30:48 +02:00
parent 16c84948c2
commit c9798f4816

View File

@ -602,23 +602,25 @@ bool VM::execSHRR(void) {
return true; return true;
} }
bool VM::execPUSH(void) { bool VM::execPUSH(void) {
// TODO: STACK < 0
uint8_t src; uint8_t src;
src = as.code[regs[IP] + 1]; src = as.code[regs[IP] + 1];
DBG_INFO(("PUSH %s\n", getRegName(src))); DBG_INFO(("PUSH %s\n", getRegName(src)));
if (regs[SP] + sizeof(uint16_t) > 0xffff) {
DBG_ERROR(("Out of bound: stack is going above 0xFFFF!\n"));
return false;
}
memcpy(&as.stack[regs[SP]], &regs[src], sizeof(uint16_t)); memcpy(&as.stack[regs[SP]], &regs[src], sizeof(uint16_t));
regs[SP] += sizeof(uint16_t); regs[SP] += sizeof(uint16_t);
return true; return true;
} }
bool VM::execPOOP(void) { bool VM::execPOOP(void) {
// TODO: STACK < 0
uint8_t dst; uint8_t dst;
dst = as.code[regs[IP] + 1]; dst = as.code[regs[IP] + 1];
DBG_INFO(("POOP %s\n", getRegName(dst))); DBG_INFO(("POOP %s\n", getRegName(dst)));
if (regs[SP] - sizeof(uint16_t) < 0) { if (regs[SP] - sizeof(uint16_t) < 0) {
DBG_ERROR(("Stack is going below 0!\n")); DBG_ERROR(("Out of bound: stack is going below 0!\n"));
return false; return false;
} }
regs[SP] -= sizeof(uint16_t); regs[SP] -= sizeof(uint16_t);