Pristine Ack-5.5
[Ack-5.5.git] / mach / 6805 / as / mach5.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 #define RCSID5 "$Id: mach5.c,v 0.3 1994/06/24 12:55:56 ceriel Exp $"
6
7 /*
8  * Motorola 6805 special routines
9  */
10
11 /* VARARGS2 */
12 branch(opc,exp,cell) register opc; expr_t cell; expr_t exp; {
13         register sm, dist;
14         int saving;
15
16         dist = exp.val - (DOTVAL + 2);
17         if((opc & 0xf0) == 0) dist -= 1;  /* bitbranch */
18         if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT))
19                 dist -= DOTGAIN;
20         sm = fitj(dist);
21         if ((exp.typ & ~S_DOT) != DOTTYP)
22                 sm = 0;
23         if (opc == 0x20 || opc == 0xAD)
24                 saving = 1;
25         else
26                 saving = 3;
27         if (small(sm,saving)) {
28                 emit1(opc);
29                 if((opc & 0xF0) == 0)   /* bit branch */
30                         emit1(cell.val);
31 #ifdef RELOCATION
32                 newrelo(exp.typ, RELPC|RELO1);
33 #endif
34                 emit1(dist);
35         } else {
36                 if (opc == 0xAD)                /* bsr */
37                         emit1(0xBD);            /* jsr */
38                 else {
39                         if (opc != 0x20) {      /* bra */
40
41                                         /* reverse condition : */
42
43                                 emit1(opc ^ 1);
44                                 if((opc & 0xF0) == 0)  /* bitbranch */
45                                         emit1(cell.val);
46                                 emit1(3);
47                         }
48                         emit1(0xCC);            /* jmp */
49                 }
50 #ifdef RELOCATION
51                 newrelo(exp.typ, RELPC|RELO2|RELBR);
52 #endif
53                 emit2(exp.val);
54         }
55 }