Something of an irony when posting a question to a site called stackoverflow - but here goes.
I have the following specification for a virtual CPU to be implemented in software (I'm choosing Java).
Each CPU of this virtual computer contains two address registers, two numeric registers, a flags register to indicate error conditions, a stack pointer, a ten word stack, and an instruction pointer
For my ten word stack I need to define what happens when you push to it when it is full. The writer of the specification has left this as assumed knowledge.
The structure of the CPU (if it were hypothetically defined in C) - is defined as follows:
struct cpu { /* structure for registers of virtual cpu */
int ax; /* address register */
int bx; /* address register */
int cx; /* numerical register */
int dx; /* numerical register */
char fl; /* flag */
char sp; /* stack pointer */
int st[10]; /* stack */
int ip; /* instruction pointer */ }
The CPU operations I have for the stack are:
case 0x0c: push_ax(ci); break; /* push ax on stack */
case 0x0d: push_bx(ci); break; /* push bx on stack */
case 0x0e: push_cx(ci); break; /* push cx on stack */
case 0x0f: push_dx(ci); break; /* push dx on stack */
case 0x10: pop_ax(ci); break; /* pop to of stack into ax */
case 0x11: pop_bx(ci); break; /* pop to of stack into bx */
case 0x12: pop_cx(ci); break; /* pop to of stack into cx */
case 0x13: pop_dx(ci); break; /* pop to of stack into dx */
Is it normal behaviour to get a stack overflow in this situation? (Pushing to a full stack).
The other hypothetical possibility is simply to kick off the bottom of the stack. (Stack as FIFO queue with size limit).
My question is: What is the expected result when pushing onto a full (virtual) CPU stack?