Stack limitato con push e pop
This commit is contained in:
parent
16c84948c2
commit
c9798f4816
@ -602,23 +602,25 @@ bool VM::execSHRR(void) {
|
||||
return true;
|
||||
}
|
||||
bool VM::execPUSH(void) {
|
||||
// TODO: STACK < 0
|
||||
uint8_t src;
|
||||
|
||||
src = as.code[regs[IP] + 1];
|
||||
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]], ®s[src], sizeof(uint16_t));
|
||||
regs[SP] += sizeof(uint16_t);
|
||||
return true;
|
||||
}
|
||||
bool VM::execPOOP(void) {
|
||||
// TODO: STACK < 0
|
||||
uint8_t dst;
|
||||
|
||||
dst = as.code[regs[IP] + 1];
|
||||
DBG_INFO(("POOP %s\n", getRegName(dst)));
|
||||
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;
|
||||
}
|
||||
regs[SP] -= sizeof(uint16_t);
|
||||
|
Loading…
Reference in New Issue
Block a user