Advertisement
Guest User

C/C++ intrinsic __stosq

a guest
Jan 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. // test.cxx
  2.  
  3. #include <stdio.h>
  4. #include <windows.h>
  5.  
  6. #include "test.h"
  7.  
  8. int __cdecl main( int argc, char* argv[ ] )
  9. {
  10. unsigned long long* ptr = (unsigned long long*) new unsigned long long [ 16 ];
  11. unsigned long long refval = (unsigned long long) setval( ptr );
  12. unsigned long long val = (unsigned long long) getval( );
  13.  
  14. printf( "refval: %I64u\n", refval );
  15. printf( "val: %I64u\n", val );
  16. printf( "*ptr: %I64u (before __stosq)\n", *ptr );
  17.  
  18. __stosq( (unsigned __int64*) ptr, (unsigned __int64) 0ui64, 16 );
  19.  
  20. printf( "*ptr: %I64u (after __stosq)\n", *ptr );
  21.  
  22. delete [] ptr;
  23.  
  24. return 0;
  25. }
  26.  
  27. // test.h
  28.  
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32.  
  33. unsigned __int64 __fastcall getval( void );
  34. unsigned __int64 __fastcall setval( unsigned __int64* refval );
  35.  
  36. #ifdef __cplusplus
  37. }
  38. #endif
  39.  
  40.  
  41.  
  42. ;Assembler code for test.cxx program
  43. ;--------------------------------------------------------------------------
  44. ;unsigned __int64 __fastcall getval( void );
  45. ;unsigned __int64 __fastcall setval( unsigned __int64* refval );
  46. ;--------------------------------------------------------------------------
  47.  
  48. .CODE
  49.  
  50. ;--------------------------------------------------------------------------
  51.  
  52. getval PROC
  53.  
  54. MOV RAX,12345678ABCDEF00H
  55. RET
  56.  
  57. getval ENDP
  58.  
  59. ;--------------------------------------------------------------------------
  60.  
  61. refval$ = 8 ; RCX
  62.  
  63. setval PROC
  64.  
  65. MOV RAX,0FEDCBA987654321H
  66. XCHG RAX,[RCX]
  67. RET
  68.  
  69. setval ENDP
  70.  
  71. ;--------------------------------------------------------------------------
  72.  
  73. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement