| | |
using STDCALL
![]() |
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 0
My homework assignment is to convert this c++ code into assembly. Here is the code
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.
Assembly Syntax (Toggle Plain Text)
void maxInt (int xVal, int yVal, int& big) { big = xVal; if ( big < yVal ) big = yVal; return; }
Assembly Syntax (Toggle Plain Text)
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
Not to be nit-picky, but void really don't have a "return".
And since maxInt never really had an input, perhaps there should
be two functions since maxInt just checks the comparisons.
I suppose it doesn't matter if you have it all in one function or not. Personal preference in design.
And since maxInt never really had an input, perhaps there should
be two functions since maxInt just checks the comparisons.
Assembly Syntax (Toggle Plain Text)
bool maxInt(int, int, int&) { ...return true if x and y have a diffrence... } void printInt(int x, int y, int big) { if(x == -9999) { ...set kill signal... } bool difference = maxInt(x, y, big); if(!diffrence) { cout << "They were the same" << endl; } else { cout << "Big is: " << big << endl; } }
I suppose it doesn't matter if you have it all in one function or not. Personal preference in design.
Last edited by MosaicFuneral; Dec 7th, 2008 at 3:52 am.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
•
•
Join Date: Oct 2008
Posts: 89
Reputation:
Solved Threads: 0
Is the right? I'm using the push and everything. I'm still not using all the variable though(xVal, yVal, and &big). How would I incorporate those into my program?
Assembly Syntax (Toggle Plain Text)
INCLUDE Irvine32.inc .data xVal DWORD ? yVal DWORD ? big 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 call ReadInt ; Enter second integer mov yVal,eax push yVal push xVal 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 ;--------------------------------------------------------------- push ebp mov ebp,esp ; Base of stack frame mov eax,[ebp + 12] ; second integer mov yVal,eax mov eax,[ebp + 8] ; first integer cmp yVal,eax jg L1 jl L5 je L3 L1: mov eax,yVal jmp L5 L3: cmp eax,-9999 jne L4 exit L4: mov edx,OFFSET messageE call WriteString pop ebp ret 8 L5: mov edx,OFFSET messageB call WriteString call WriteInt pop ebp ret 8 maxInt ENDP ; Ends maxInt PROC END main
•
•
Join Date: Nov 2008
Posts: 23
Reputation:
Solved Threads: 2
Assembly Syntax (Toggle Plain Text)
INCLUDE Irvine32.inc maxInt proto xVal:DWORD, yVal:DWORD ;..................... push 2 ; yVal push 3 ; xVal call maxInt ;..................... maxInt proc xVal:DWORD, yVal:DWORD mov eax, xVal cmp eax, yVal jl lbl1 jg lbl2 cmp eax, -9999 jne lbl3 ;exit lbl3: ;they are equal ;exit lbl1: ;yVal more ;exit lbl2: ;xVal more ;exit maxInt endp
Last edited by low_coder; Dec 8th, 2008 at 5:04 pm.
•
•
Join Date: Nov 2008
Posts: 23
Reputation:
Solved Threads: 2
Assembly Syntax (Toggle Plain Text)
INCLUDE Irvine32.inc maxInt proto xVal:DWORD, yVal:DWORD ;..................... push 2 ; yVal push 3 ; xVal call maxInt ;..................... maxInt proc xVal:DWORD, yVal:DWORD mov eax, xVal cmp eax, yVal jl lbl1 jg lbl2 cmp eax, -9999 jne lbl3 ;exit lbl3: ;they are equal ;exit lbl1: ;yVal more ;exit lbl2: ;xVal more ;exit maxInt endp
![]() |
Similar Threads
- Printing of a Form in VB.NET? (VB.NET)
- A multilingual coded Hello World! thread (Legacy and Other Languages)
- 500 ways to print [1..10]! (IT Professionals' Lounge)
- find files of certain type... (Assembly)
- Making a registry key (Assembly)
- copy string and convert to upper case (Assembly)
- I'm new (Assembly)
- Using Global Low-Level Hooks Without Using A Dll (Computer Science)
- Introduction to 80 x 86 Assembly Language and Computer Architecture - no CD - help (Assembly)
Other Threads in the Assembly Forum
- Previous Thread: wat does this do
- Next Thread: PCSpim/Assembly HELP
| Thread Tools | Search this Thread |





