conaddr.ssa (1198B)
1 # test amd64 addressing modes 2 3 export 4 function w $f0(l %o) { 5 @start 6 %addr =l add $a, %o 7 %char =w loadub %addr 8 ret %char 9 } 10 11 export 12 function w $f1(l %o) { 13 @start 14 %o1 =l mul %o, 1 15 %addr =l add 10, %o1 16 %char =w loadub %addr 17 ret %char 18 } 19 20 export 21 function w $f2(l %o1, l %o2) { 22 @start 23 %o22 =l mul %o2, 2 24 %o =l add %o1, %o22 25 %addr =l add $a, %o 26 %char =w loadub %addr 27 ret %char 28 } 29 30 export 31 function l $f3(l %o) { 32 @start 33 %addr =l add %o, $a 34 ret %addr 35 } 36 37 export 38 function $f4() { 39 @start 40 storel $p, $p 41 ret 42 } 43 44 export 45 function $writeto0() { 46 @start 47 storel 0, 0 48 ret 49 } 50 51 # >>> driver 52 # #include <stdlib.h> 53 # #include <signal.h> 54 # char a[] = "qbe rocks"; 55 # void *p; 56 # int ok; 57 # extern unsigned f0(long), f1(long), f2(long, long); 58 # extern char *f3(long); 59 # extern void f4(), writeto0(); 60 # void h(int sig, siginfo_t *si, void *unused) { 61 # ok += si->si_addr == 0; 62 # exit(!(ok == 6)); 63 # } 64 # int main() { 65 # struct sigaction sa = {.sa_flags=SA_SIGINFO, .sa_sigaction=h}; 66 # sigemptyset(&sa.sa_mask); sigaction(SIGSEGV, &sa, 0); 67 # ok += f0(2) == 'e'; 68 # ok += f1((long)a-5) == 'o'; 69 # ok += f2(4, 2) == 's'; 70 # ok += *f3(0) == 'q'; 71 # f4(); 72 # ok += p == &p; 73 # writeto0(); /* will segfault */ 74 # } 75 # <<<