Suppose we were to call a procedure named ProcTwo, which calculates the sum of t
ID: 3843518 • Letter: S
Question
Suppose we were to call a procedure named ProcTwo, which calculates the sum of the elements of an array of 32-bit words and returns the sum in EAX. The following code calls ProcTwo: .data myray dWORD 1012b, 2023b, 3034h, 4045h .code push offset myray push sizeof myray call ProcTwo; EAX = sum Write the implementation of ProcTwo, using explicit stack parameters (such as [ebp+n]). Follow other common conventions regarding the saving and restoring of registers. Restore the slack pointer using the STDCALL calling convention, and assume a 32-bit memory model.Explanation / Answer
The stack is a simple but important example of an abstract data type. It is used to store elements where the Last element In is the First one Out (LIFO). Anyone with a cluttered desk or an overfull sink of washing-up will be familiar with a stack. New elements are added or pushed onto the top of the stack. The first element to be removed or popped is taken from the top - the last one in. All recursive programming languages use an implicit system-stack to allocate space for local variables of routines as they are called. Some algorithms require the use of an explicit stack.
A small "pocket-calculator" program is given here. The input language is reverse-Polish (after Jan Lukasiewicz) or postfix notation which has the advantage that no brackets are needed. At least one commercially available pocket-calculator uses this notation.
The program uses a single stack which is implemented as a module in the following sections. The module specifies a clean interface between the use of the stack and the implementation of the stack. The latter can be changed so long as the interface is adhered to and the calculator program will still work. The implementation(s) can be verified and tested to ensure compliance with the interface. Use of modules in this way is a useful technique in the management of large programming projects.
Each operand is pushed onto the stack. Each operator takes two operands from the top of the stack and pushes its result onto the stack
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.