943,651 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1964
  • Assembly RSS
Dec 2nd, 2008
0

using STDCALL

Expand Post »
My homework assignment is to convert this c++ code into assembly. Here is the code
Assembly Syntax (Toggle Plain Text)
  1. void maxInt (int xVal, int yVal, int& big)
  2. {
  3. big = xVal;
  4. if ( big < yVal )
  5. big = yVal;
  6. return;
  7. }
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)
  1. INCLUDE Irvine32.inc
  2. .data
  3.  
  4. xVal DWORD ?
  5. yVal DWORD ?
  6.  
  7. Message BYTE "Enter each integer on sepatate line. Enter -9999 for both to quit.",0dh,0ah,0
  8. MessageE BYTE "Integers are equal.",0
  9. MessageB BYTE "The larger integer was: ",0
  10.  
  11. .code
  12. main PROC
  13. mov edx,OFFSET Message
  14. call WriteString
  15. call ReadInt ; Enter first integer
  16. mov xVal,eax ; Stores the first value in xVal
  17. call ReadInt ; Enter second integer
  18. mov yVal,eax ; Stores the second value in yVal
  19. call maxInt ; Calls the maxInt PROC
  20. call crlf ; Carriage return line feed
  21. call main ; Goes back to main
  22.  
  23. main ENDP
  24.  
  25. ;---------------------------------------------------------------
  26. maxInt PROC
  27. ;
  28. ; Calculates and returns the larger of the two integers entered by
  29. ; the user.
  30. ;
  31. ; Receives: xVal, yVal, the two integers
  32. ; Returns: eax
  33. ;---------------------------------------------------------------
  34.  
  35. mov eax,xVal ; Moves xVal to eax
  36. cmp yVal,eax ; Compares yVal to eax
  37. je L1 ; Jumps to L1 if equal
  38. jg L3 ; Jumps to L3 if eax > yVal
  39. jl L4 ; Jumps to L4 if eax < yVal
  40.  
  41. L1: cmp eax,-9999 ; Compares -9999 to eax
  42. jne L2 ; Jumps to L2 if eax does not equal -9999
  43. exit ; Exits program if eax equals -9999
  44.  
  45. L2: mov edx,OFFSET MessageE
  46. call WriteString
  47. ret ; Returns back to main
  48.  
  49. L3: mov eax,yVal ; Moves the larger integer(yVal) to eax
  50. jmp L4 ; Jumps to L4
  51.  
  52. L4: mov edx,OFFSET MessageB
  53. call WriteString
  54. call WriteInt ; Displays the larger integer
  55. ret ; Returns back to main
  56.  
  57. maxInt ENDP ; Ends maxInt PROC
  58.  
  59. END main
Similar Threads
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Dec 4th, 2008
1

Re: using STDCALL

;Hi.
;Actually why did you compare eax with -9999 ?
cmp eax,-9999 ;?
----------------------------------------------------------------
;stdcall is pushing on the stack values in the opposite order:
push val2
push val1
call myfunc
Reputation Points: 40
Solved Threads: 4
Junior Poster in Training
low_coder is offline Offline
55 posts
since Nov 2008
Dec 6th, 2008
0

Re: using STDCALL

Entering -9999 for both ends the program. Ok, I think I understand whats goin on now. I'll try that and see what happens.
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Dec 7th, 2008
0

Re: using STDCALL

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.

Assembly Syntax (Toggle Plain Text)
  1. bool maxInt(int, int, int&)
  2. {
  3. ...return true if x and y have a diffrence...
  4. }
  5.  
  6. void printInt(int x, int y, int big)
  7. {
  8. if(x == -9999) { ...set kill signal... }
  9.  
  10. bool difference = maxInt(x, y, big);
  11. if(!diffrence) { cout << "They were the same" << endl; }
  12. else
  13. {
  14. cout << "Big is: " << big << endl;
  15. }
  16. }

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.
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008
Dec 8th, 2008
0

Re: using STDCALL

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)
  1. INCLUDE Irvine32.inc
  2. .data
  3.  
  4. xVal DWORD ?
  5. yVal DWORD ?
  6. big DWORD ?
  7.  
  8. Message BYTE "Enter each integer on sepatate line. Enter -9999 for both to quit.",0dh,0ah,0
  9. MessageE BYTE "Integers are equal.",0
  10. MessageB BYTE "The larger integer was: ",0
  11.  
  12. .code
  13. main PROC
  14. mov edx,OFFSET Message
  15. call WriteString
  16. call ReadInt ; Enter first integer
  17. mov xVal,eax
  18. call ReadInt ; Enter second integer
  19. mov yVal,eax
  20. push yVal
  21. push xVal
  22. call maxInt ; Calls the maxInt PROC
  23. call crlf ; Carriage return line feed
  24. call main ; Goes back to main
  25.  
  26. main ENDP
  27.  
  28. ;---------------------------------------------------------------
  29. maxInt PROC
  30. ;
  31. ; Calculates and returns the larger of the two integers entered by
  32. ; the user.
  33. ;
  34. ; Receives: xVal, yVal, the two integers
  35. ; Returns: eax
  36. ;---------------------------------------------------------------
  37.  
  38. push ebp
  39. mov ebp,esp ; Base of stack frame
  40. mov eax,[ebp + 12] ; second integer
  41. mov yVal,eax
  42. mov eax,[ebp + 8] ; first integer
  43. cmp yVal,eax
  44. jg L1
  45. jl L5
  46. je L3
  47.  
  48. L1: mov eax,yVal
  49. jmp L5
  50.  
  51. L3: cmp eax,-9999
  52. jne L4
  53. exit
  54.  
  55. L4: mov edx,OFFSET messageE
  56. call WriteString
  57. pop ebp
  58. ret 8
  59.  
  60. L5: mov edx,OFFSET messageB
  61. call WriteString
  62. call WriteInt
  63. pop ebp
  64. ret 8
  65.  
  66. maxInt ENDP ; Ends maxInt PROC
  67.  
  68. END main
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Dec 8th, 2008
0

Re: using STDCALL

Assembly Syntax (Toggle Plain Text)
  1. INCLUDE Irvine32.inc
  2. maxInt proto xVal:DWORD, yVal:DWORD
  3. ;.....................
  4. push 2 ; yVal
  5. push 3 ; xVal
  6. call maxInt
  7. ;.....................
  8. maxInt proc xVal:DWORD, yVal:DWORD
  9. mov eax, xVal
  10. cmp eax, yVal
  11. jl lbl1
  12. jg lbl2
  13. cmp eax, -9999
  14. jne lbl3
  15. ;exit
  16. lbl3:
  17. ;they are equal
  18. ;exit
  19. lbl1:
  20. ;yVal more
  21. ;exit
  22. lbl2:
  23. ;xVal more
  24. ;exit
  25. maxInt endp
;didnt try must work.
Last edited by low_coder; Dec 8th, 2008 at 5:04 pm.
Reputation Points: 40
Solved Threads: 4
Junior Poster in Training
low_coder is offline Offline
55 posts
since Nov 2008
Dec 8th, 2008
0

Re: using STDCALL

Assembly Syntax (Toggle Plain Text)
  1. INCLUDE Irvine32.inc
  2. maxInt proto xVal:DWORD, yVal:DWORD
  3. ;.....................
  4. push 2 ; yVal
  5. push 3 ; xVal
  6. call maxInt
  7. ;.....................
  8. maxInt proc xVal:DWORD, yVal:DWORD
  9. mov eax, xVal
  10. cmp eax, yVal
  11. jl lbl1
  12. jg lbl2
  13. cmp eax, -9999
  14. jne lbl3
  15. ;exit
  16. lbl3:
  17. ;they are equal
  18. ;exit
  19. lbl1:
  20. ;yVal more
  21. ;exit
  22. lbl2:
  23. ;xVal more
  24. ;exit
  25. maxInt endp
;didnt try must work.
Reputation Points: 40
Solved Threads: 4
Junior Poster in Training
low_coder is offline Offline
55 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: wat does this do
Next Thread in Assembly Forum Timeline: PCSpim/Assembly HELP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC