Suppose we were to call a procedure named ProcOne, passing it two name parameter
ID: 3843913 • 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 v1 dword 5 push eax v2 dword 7 mov ax, 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. Suppose we were to call a procedure named ProcTwo, which calculates the sum of the elements of an array of 16-bit words and returns the sum in EAX. The following code calls ProcTwo:. data myArray WORD 100h, 200h, 300h, 500h push LENGTHOF myArray push OFFSET myArray 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 stack pointer using the usual calling convention, and assume a 32-bit memory model. Tract Showing the stack frame at each call The Accum Procedure main PRCC mov eax, 0 push 9 call Accum M1: call DumpRegs exit main EBDP Accum PROC push ebp mov ebp, esp JLE L1 mov ebx, [ebp + B] cmp ebx, 3 add eax, ebx sub ebx, 3 push ebx call Accum L1: pop ebp ret 4 Accum ENDP What will be the value of EAX when DumpRegs is called.Explanation / Answer
.globl _square_rt _square_rt: push ebp mov ebp,esp push ebx #using ebx, so save it mov eax,[ebp+12] #eax gets low mov ecx,[ebp+16] #ecx gets high sub ecx,1 #now ecx has high-1cmp eax,ecx # if low >= high-1 jge DONE # eax already contains low, just return mov ecx,[ebp+16] #reload ecx with high mov edx,eax #edx gets mid, first get low add edx,ecx #add high shr edx #shift right by one mov ebx,edx #ebx will hold mid*mid imul ebx,ebx cmp ebx,[ebp+8] #if mid*mid > x jg GREATER # jump to GREATER #otherwise call square_rt(x,mid,high) push ecx #push high push edx #push mid push DWORD PTR [ebp+8] #push x call _square_rt add esp,12 #adjust stack jmp DONE #we’re done, result is already in eax GREATER: #calling square_rt(x,low, mid) push edx #push mid push eax #push low push DWORD PTR [ebp+8] #push x call _square_rt add esp,12 #adjust stack #we’re done, result is already in eax DONE: pop ebx #restore ebx pop ebp ret
.globl _square_rt _square_rt: push %ebp mov %esp,%ebp push %ebx #using ebx, so save it mov 12(%ebp),%eax #eax gets low mov 16(%ebp),%ecx #ecx gets high sub $1,%ecx #now ecx has high-1 cmp %ecx,%eax # if low >= high jge DONE # eax already contains low, just returnmov 16(%ebp),%ecx #reload ecx with high mov %eax,%edx #edx gets mid, first get low add %ecx,%edx #add high shr %edx #shift right by one mov %edx,%ebx #ebx will hold mid*mid imul %ebx,%ebx cmp 8(%ebp),%ebx #if mid*mid > x jg GREATER # jump to GREATER #otherwise call square_rt(x,mid,high) push %ecx #push high push %edx #push mid pushl 8(%ebp) #push x call _square_rt add $12,%esp #adjust stack jmp DONE #were done, result is already in %eax GREATER: #calling square_rt(x,low, mid) push %edx #push mid push %eax #push low pushl 8(%ebp) #push x call _square_rt add $12,%esp #adjust stack jmp DONE #result is already in %eax DONE: pop %ebx #restore ebx pop %ebp ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.