Guest User

Untitled

a guest
Jan 24th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. int get_c_from_a (int a)
  2. {
  3. struct s tmp;
  4. tmp = get_some_values(a);
  5. return tmp.c;
  6. }
  7.  
  8. ======
  9.  
  10. get_c_from_a:
  11.  
  12. ; prolog - setup the local frame
  13. push ebp
  14. mov ebp, esp
  15.  
  16. sub esp, 0xc ; make room on the stack for tmp (3 * 4-byte ints)
  17.  
  18. mov eax, [ebp+8] ; eax = arg1 to get_c_from_a = a
  19. push eax ; pushing it as arg1 to get_some_values
  20.  
  21. lea eax, [ebp-0xc] ; eax = &tmp
  22. push eax ; push &tmp (we only push a return value pointer for complex return objects)
  23.  
  24. call get_some_values
  25.  
  26. ; our struct now looks like
  27. ; [ebp-c]: tmp.a = a + 1
  28. ; [ebp-8]: tmp.b = a + 2
  29. ; [ebp-4]: tmp.c = a + 3
  30.  
  31. ; and we want to return tmp.c in eax
  32. mov eax, [ebp-4]
  33.  
  34. ; epilog - restores esp and ebp to their entry values, cleaning up our stack usage
  35. mov esp, ebp
  36. pop ebp
  37. ret
  38.  
Advertisement
Add Comment
Please, Sign In to add comment