| 1 |
/* |
| 2 |
* test source file for assembling to ELF |
| 3 |
* build with: |
| 4 |
* nasm -f elf elftest.asm |
| 5 |
* gcc -o elftest elftest.c elftest.o |
| 6 |
* (assuming your gcc is ELF) |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
#include <inttypes.h> |
| 11 |
|
| 12 |
extern int lrotate(int32_t, int); |
| 13 |
extern void greet(void); |
| 14 |
extern int8_t asmstr[]; |
| 15 |
extern void *selfptr; |
| 16 |
extern void *textptr; |
| 17 |
extern int integer, commvar; |
| 18 |
|
| 19 |
int main(void) |
| 20 |
{ |
| 21 |
|
| 22 |
printf("Testing lrotate: should get 0x00400000, 0x00000001\n"); |
| 23 |
printf("lrotate(0x00040000, 4) = 0x%08lx\n", lrotate(0x40000, 4)); |
| 24 |
printf("lrotate(0x00040000, 14) = 0x%08lx\n", lrotate(0x40000, 14)); |
| 25 |
|
| 26 |
printf("This string should read `hello, world': `%s'\n", asmstr); |
| 27 |
|
| 28 |
printf("The integers here should be 1234, 1235 and 4321:\n"); |
| 29 |
integer = 1234; |
| 30 |
commvar = 4321; |
| 31 |
greet(); |
| 32 |
|
| 33 |
printf("These pointers should be equal: %p and %p\n", &greet, textptr); |
| 34 |
|
| 35 |
printf("So should these: %p and %p\n", selfptr, &selfptr); |
| 36 |
|
| 37 |
return 0; |
| 38 |
} |