Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void stack_in_bounds(struct machine *machine)
- {
- // make sure that 0 <= SP <= 15
- // SP is signed, so no need to check for negative
- assert(machine->registers.stack_pointer < 16);
- }
- void stack_push(struct machine *machine, uint16_t value)
- {
- stack_in_bounds(machine);
- machine->stack[machine->registers.stack_pointer] = value;
- machine->registers.stack_pointer++;
- }
- uint16_t stack_pop(struct machine* machine)
- {
- machine->registers.stack_pointer--;
- stack_in_bounds(machine);
- /* intuitively, this seems to pop the _2nd_ value, not the top */
- return machine->stack[machine->registers.stack_pointer];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement