My homework assignment is to convert this c++ code into assembly. Here is the code
void maxInt (int xVal, int yVal, int& big)
{
big = xVal;
if ( big < yVal )
big = yVal;
return;
}
I have successfully created a program that will find the larger integer and return it, but we have to use the STDCALL technique. I am not real sure on how to do that. Would I push xVal, yVal, and big on the stack, then call maxInt? The code I have now just stores the entered integers in xVal and yVal and uses eax to do all my cmp's and everything and I don't push or pop anything on the stack. Here is my code. I use the Irvine routine that came with my book but everything is pretty self explanitory if you aren't familiar with these. Any help or pointers would be greatly appreciated.
INCLUDE Irvine32.inc
.data
xVal DWORD ?
yVal DWORD ?
Message BYTE "Enter each integer on sepatate line. Enter -9999 for both to quit.",0dh,0ah,0
MessageE BYTE "Integers are equal.",0
MessageB BYTE "The larger integer was: ",0
.code
main PROC
mov edx,OFFSET Message
call WriteString
call ReadInt ; Enter first integer
mov xVal,eax ; Stores the first value in xVal
call ReadInt ; Enter second integer
mov yVal,eax ; Stores the second value in yVal
call maxInt ; Calls the maxInt PROC
call crlf ; Carriage return line feed
call main ; Goes back to main
main ENDP
;---------------------------------------------------------------
maxInt PROC
;
; Calculates and returns the larger of the two integers entered by
; the user.
;
; Receives: xVal, yVal, the two integers
; Returns: eax
;---------------------------------------------------------------
mov eax,xVal ; Moves xVal to eax
cmp yVal,eax ; Compares yVal to eax
je L1 ; Jumps to L1 if equal
jg L3 ; Jumps to L3 if eax > yVal
jl L4 ; Jumps to L4 if eax < yVal
L1: cmp eax,-9999 ; Compares -9999 to eax
jne L2 ; Jumps to L2 if eax does not equal -9999
exit ; Exits program if eax equals -9999
L2: mov edx,OFFSET MessageE
call WriteString
ret ; Returns back to main
L3: mov eax,yVal ; Moves the larger integer(yVal) to eax
jmp L4 ; Jumps to L4
L4: mov edx,OFFSET MessageB
call WriteString
call WriteInt ; Displays the larger integer
ret ; Returns back to main
maxInt ENDP ; Ends maxInt PROC
END main