int StackPop if stackpointer 0 cerr Stack underflown return 0 stackpointer cout

Int stackpop if stackpointer 0 cerr stack underflown

This preview shows page 17 - 19 out of 102 pages.

int Stack::Pop () { if (stackpointer == 0) { cerr << "Stack underflow!\n"; return 0; } stackpointer--; cout << "Popped " << stack[stackpointer] << " from stack\n"; return (stack[stackpointer]); } //********************************************************************* * void Stack::ShowStack () { int i; for (i = stacksize-1; i >= 0; i--) { cout << "stack[" << i << "] = " << stack[i]; if (i == stackpointer) { cout << " <<-- Pointer\n"; } else { cout << endl; } } } In this example, only numbers are stored. At the hardware level, this kind of stack is used by the CPU to store addresses and registers during machine-code subroutine jumps. Operating systems also use software controlled stacks during the execution of users' programs. High level languages subroutines can have local variables which are also copied to the stack as one large stack frame during the execution of subroutines. 2.3 Input/Output Input arrives at the computer at unpredictable intervals. The system must be able to detect its arrival and respond to it. 2.3.1 Interrupts Interrupts are hardware triggered signals which cause the CPU to stop what it is doing and jump to a special subroutine. Interrupts normally arrive from hardware devices, such as when the user presses a key on the keyboard, or the disk device has fetched some data from the disk. They can also be generated in software by errors like division by zero or illegal memory address . When the CPU receives an interrupt, it saves the contents of its registers on the hardware stack and jumps to a special routine which will determine the cause of the interrupt and respond to it appropriately. Interrupts occur at different levels. Low level interrupts can be interrupted by high level interrupts. Interrupt handling routines have to work quickly, or the computer will be drowned in the business of servicing
Image of page 17
interrupts. For certain critical operations, low level interrupts can be ignored by setting a mask (See also the generalization of this for multiuser systems in chapter 4). There is no logical difference between what happens during the execution of an interrupt routine and a subroutine. The difference is that interrupt routines are triggered by events , whereas software subroutines follow a prearranged plan. An important area is the interrupt vector . This is a region of memory reserved by the hardware for servicing of interrupts. Each interrupt has a number from zero to the maximum number of interrupts supported on the CPU; for each interrupt, the interrupt vector must be programmed with the address of a routine which is to be executed when the interrupt occurs. i.e. when an interrupt occurs, the system examines the address in the interrupt vector for that interrupt and jumps to that location. The routine exits when it meets an RTI (return from interrupt) instruction. 2.3.2 Buffers The CPU and the devices attached to it do not work at the same speed. Buffers are therefore needed to store incoming or outgoing information temporarily, while it is waiting to be picked up by the other party. A buffer is simply an area of memory which works as a waiting area. It is a first-in first-out (FIFO) data structure or queue .
Image of page 18
Image of page 19

You've reached the end of your free preview.

Want to read all 102 pages?

  • One '20

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors