这是一个两部分的作业。首先,我必须弄清楚如何使用堆栈将引用参数发送到名为 pow 的过程,我认为我正确地使用push offset result
了这个任务的第二部分,我完全一无所知,我已经阅读并阅读了我的文本,但我是仍然无法弄清楚我如何才能完成我需要做的事情。发送参考参数后,我需要将 pow 过程中的计算结果存储在参考参数中,以便稍后在程序中输出。到目前为止,我已经尝试了一些不同的方法,但无济于事。代码被注释了,所以那些熟悉汇编的人应该明白我在做什么。如果有人可以帮助我,我将不胜感激。谢谢
INCLUDE Irvine32.inc
.data
XPrompt BYTE "Enter the value of the base(X):",0
YPrompt BYTE "Enter the value of the exponent(Y):",0
ResultMessage BYTE "X to the power of Y is",0
result DWORD ?
.code
main PROC
call Clrscr
;;;;Prompt for X
mov edx,OFFSET XPrompt
call WriteString
call ReadInt
push eax ;;;;pass the 1st number to POW
;;;;this will represent the base
;;;; Prompt for Y
mov edx,OFFSET YPrompt
call WriteString
call ReadInt
push eax ;;;;pass the 2nd number to POW
;;;;this will represent the EXPONENT
push OFFSET result ;;;;pass the third parameter to pow, using offset makes it a reference parameter
call Pow
;;; Print Result (Assumes the answer is in eax)
mov edx,OFFSET ResultMessage
call WriteString
;;;;;;;;;;;;;;;;;NOTE: NEW "POW" MODIFICATIONS HERE;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov eax,result ; If the pow function correctly returns it answer by reference
; then this should be all that's necessary to print
; the answer with the call to "WriteInt"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call WriteInt
call ReadInt ;;;; screen pause
exit
main ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Pow PROC
COMMENT !
PUT FUNCTION CODE IN THIS SECTION
This current pow function returns its answer via register "eax." Modify it as necessary
so that it returns its answer by a reference parameter. In C++ the function interface/prototype
would look like:
void pow(int base,int exp, int & result)
where "base" is the base and "exp" is the exponent. In other words "pow" should calculate "base" to the
power of "exp," then return the answer via "result." Let your function return its result via a
3rd REFERENCE parameter "result." Which will be a REFERENCE parameter on the stack.
!
base EQU DWORD PTR [ebp + 12]
exponent EQU DWORD PTR [ebp + 8]
push ebp
mov ebp, esp
push ecx ;<------------ecx must also be preserved since it is modified
; by the "loop" instruction.
mov ecx, exponent ;set ecx as our counter
mov eax, 1 ; eax will be our multiplier
L1:
mul base
loop L1
pop ecx ;<------------restore ecx
pop ebp ;<------------restore ebp
ret 8
Pow ENDP
END main