Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose we were to call a procedure named ProcOne, passing it two name parameter

ID: 3843900 • Letter: S

Question


Suppose we were to call a procedure named ProcOne, passing it two name parameters. The procedure adds the two parameters and returns their sum in EAX: .data Mov eax, v 1 v 1 dword 5 push eax v2 dword 7 mov x, v2 push eax call ProcOne; EAX = sum Create the implementation of ProcOne, using explicit stack parameters (such as [ebp + n]). Follow other common conventions regarding the saving and restoring of registers. Restore the stack pointer using the STDCALL calling convention, and assume a 32-bit memory model.

Explanation / Answer

.data addr_stack dd 100 dup(0) ; hope that 100 addresses is enough! stack_ptr dd ? ; stack initialization code lea EDX, addr_stack mov stack_ptr, EDX ; one call lea EAX, rtn_point jmp proc1 rtn_point: proc1: ; 1st instruction of procedure here ; push return address on stack mov [EDX], EAX add EDX, 4 . . . lea EAX, rtn_point_nested jmp proc2 rtn_point_nested: . . . ; pop retn address off stack sub EDX, 4 mov EAX, [EDX] jmp [EAX] proc2: ; 1st instruction of procedure here . . . jmp [EAX]