using STDCALL

Reply

Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

using STDCALL

 
0
  #1
Dec 2nd, 2008
My homework assignment is to convert this c++ code into assembly. Here is the code
  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.
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 23
Reputation: low_coder is an unknown quantity at this point 
Solved Threads: 2
low_coder low_coder is offline Offline
Newbie Poster

Re: using STDCALL

 
1
  #2
Dec 4th, 2008
;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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

Re: using STDCALL

 
0
  #3
Dec 6th, 2008
Entering -9999 for both ends the program. Ok, I think I understand whats goin on now. I'll try that and see what happens.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 941
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: using STDCALL

 
0
  #4
Dec 7th, 2008
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.

  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.
"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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 89
Reputation: sfrider0 is an unknown quantity at this point 
Solved Threads: 0
sfrider0 sfrider0 is offline Offline
Junior Poster in Training

Re: using STDCALL

 
0
  #5
Dec 8th, 2008
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?
  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 23
Reputation: low_coder is an unknown quantity at this point 
Solved Threads: 2
low_coder low_coder is offline Offline
Newbie Poster

Re: using STDCALL

 
0
  #6
Dec 8th, 2008
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 23
Reputation: low_coder is an unknown quantity at this point 
Solved Threads: 2
low_coder low_coder is offline Offline
Newbie Poster

Re: using STDCALL

 
0
  #7
Dec 8th, 2008
  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC