kohlrak

Untitled

Jul 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. [kohlrak@kohlrak-server tmixed]$ dir
  2. asm.S main.cpp makefile
  3. [kohlrak@kohlrak-server tmixed]$ cat makefile
  4. all:
  5. gcc main.cpp asm.S -o main
  6. run:
  7. make all
  8. ./main 37352
  9. [kohlrak@kohlrak-server tmixed]$ cat main.cpp
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. extern int bswap(int x); //extern "C" so i don't have to bother with mangling
  14.  
  15. int main(int argc, char** argv){
  16. int le=atoi(argv[1]);
  17. printf("LE: 0x%08x\nBE: 0x%08x\n", le, bswap(le));
  18. return 0;
  19. }
  20. [kohlrak@kohlrak-server tmixed]$ cat asm.S
  21. .intel_syntax noprefix
  22. .code32
  23.  
  24. .global _Z5bswapi #C++ name mangling: name is bswap, i is for integer input. Don't blame me, blame whomever wrote the ABI, but it could be made simpler if you don't want to bother with that XD
  25.  
  26. .section .text
  27.  
  28. _Z5bswapi:
  29. mov eax, [esp+4] #esp+0 is return address, +4 is first param, +8 is second param, +12 is third param, and so on
  30. bswap eax #big endian -- little endian conversion instruction
  31. ret
Advertisement
Add Comment
Please, Sign In to add comment