author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:51:15 +0200 | |
changeset 81 | 6cfca66d2f01 |
parent 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
5
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
/** |
77 | 2 |
* asm/main.c |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
5
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
*/ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
#include <stdio.h> |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
#include <stdlib.h> |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
#include <unistd.h> |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
#include <signal.h> |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
10 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
#ifndef TIMEOUT |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
#define TIMEOUT 500 |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
#endif |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
int get_sp (); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
void sigendian () |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
{ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
unsigned short word = 0x1234; |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
unsigned char *p = (unsigned char *)&word; |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
22 |
signal (SIGUSR1, sigendian); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
printf ("%s Endian System\n", (p[0] == 0x34) ? "Little" : "Big"); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
} |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
25 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
void sigproc () |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
{ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
signal (SIGINT, sigproc); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
29 |
printf ("Stack-Pointer is at %08x\n", get_sp ()); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
} |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
void sigquit () |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
{ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
printf ("Hmm... You got it, man!\n"); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
exit (0); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
} |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
int main (int argc, char **argv) |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
{ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
signal (SIGINT, sigproc); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
signal (SIGUSR1, sigendian); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
signal (SIGQUIT, sigquit); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
43 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
44 |
for (;;) |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
45 |
usleep (TIMEOUT); |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
return EXIT_FAILURE; |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
48 |
} |