Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define NUM 0x12345678
  4.  
  5. int main(void)
  6. {
  7. size_t n = NUM;
  8. size_t rot_left;
  9. size_t rot_right;
  10.  
  11. __asm__ (""
  12. /* TODO: Use rol instruction to shift n by 8 bits left.
  13. * Place result in rot_left variable.
  14. */
  15. "mov eax, %0\n"
  16. "rol eax,8\n"
  17. "mov %1,eax\n"
  18.  
  19. /* TODO: Use ror instruction to shift n by 8 bits right.
  20. * Place result in rot_right variable.
  21. */
  22. "mov ecx, %0\n"
  23. "rol ecx,8\n"
  24. "mov %2, ecx\n"
  25. /* TODO: Declare output variables - preceded by ':'. */
  26. /* TODO: Declare input variables - preceded by ':'. */
  27. /* TODO: Declared used registers - preceded by ':'. */
  28.  
  29. :"=r"(rot_left),
  30. "=r"(rot_right)
  31. :"r"(n)
  32. : "eax", "ecx");
  33. /* NOTE: Output variables are passed by address, input variables
  34. * are passed by value.
  35. */
  36.  
  37. printf("init: 0x%08x, rot_left: 0x%08x, rot_right: 0x%08x\n",
  38. n, rot_left, rot_right);
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement