[kohlrak@kohlrak-server tmixed]$ dir
asm.S main.cpp makefile
[kohlrak@kohlrak-server tmixed]$ cat makefile
all:
gcc main.cpp asm.S -o main
run:
make all
./main 37352
[kohlrak@kohlrak-server tmixed]$ cat main.cpp
#include <stdio.h>
#include <stdlib.h>
extern int bswap(int x); //extern "C" so i don't have to bother with mangling
int main(int argc, char** argv){
int le=atoi(argv[1]);
printf("LE: 0x%08x\nBE: 0x%08x\n", le, bswap(le));
return 0;
}
[kohlrak@kohlrak-server tmixed]$ cat asm.S
.intel_syntax noprefix
.code32
.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
.section .text
_Z5bswapi:
mov eax, [esp+4] #esp+0 is return address, +4 is first param, +8 is second param, +12 is third param, and so on
bswap eax #big endian -- little endian conversion instruction
ret
Comments