mach5.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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$"
  6. /*
  7. * Motorola 6809 special routines
  8. */
  9. branch(opc, exp)
  10. register int opc;
  11. expr_t exp;
  12. {
  13. register int sm, dist;
  14. int saving;
  15. dist = exp.val - (DOTVAL + 2);
  16. if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT))
  17. dist -= DOTGAIN;
  18. sm = fitb(dist);
  19. if ((exp.typ & ~S_DOT) != DOTTYP)
  20. sm = 0;
  21. if (opc == 0x8D || opc == 0x20)
  22. saving = 1;
  23. else
  24. saving = 2;
  25. if ((sm = small(sm,saving)) == 0) {
  26. dist--;
  27. if (opc == 0x8D) /* bsr */
  28. opc = 0x17;
  29. else if (opc == 0x20) /* bra */
  30. opc = 0x16;
  31. else {
  32. emit1(0x10);
  33. dist--;
  34. }
  35. }
  36. emit1(opc);
  37. if (sm == 0) {
  38. #ifdef RELOCATION
  39. if (rflag != 0 && PASS_RELO)
  40. newrelo(exp.typ, RELPC|RELO2|RELBR);
  41. #endif
  42. emit2(dist);
  43. } else
  44. emit1(lowb(dist));
  45. }
  46. regno(r) register r; {
  47. switch (r) {
  48. case X: return 0;
  49. case Y: return 0x20;
  50. case U: return 0x40;
  51. case S: return 0x60;
  52. }
  53. return -1;
  54. }
  55. emit1or2(n) {
  56. if (n & ~0xFF)
  57. emit1(n >> 8);
  58. emit1(n);
  59. }
  60. offset(reg, exp, ind)
  61. register int reg, ind;
  62. expr_t exp;
  63. {
  64. if (reg == PC) {
  65. int sm, dist;
  66. dist = exp.val - (DOTVAL + 2);
  67. if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT))
  68. dist -= DOTGAIN;
  69. sm = fitb(dist);
  70. if ((exp.typ & S_TYP) != DOTTYP)
  71. sm = 0;
  72. if (small(sm,1)) {
  73. emit1(0x8C + ind);
  74. emit1(dist);
  75. } else {
  76. emit1(0x8D + ind);
  77. emit1((dist-1)>>8);
  78. emit1(dist - 1);
  79. }
  80. } else if ((reg = regno(reg)) < 0)
  81. serror("register error");
  82. else if ((exp.typ & S_TYP) == S_ABS && exp.val == 0)
  83. emit1(0x84 + reg + ind); /* XOP 0, REG == XOP , REG */
  84. else if (ind == 0 && (exp.typ & S_TYP) == S_ABS &&
  85. -16 <= exp.val && exp.val <= 15
  86. )
  87. emit1(reg + ind + (exp.val & 037));
  88. else if ((exp.typ&S_TYP)==S_ABS && -128<=exp.val && exp.val<=127) {
  89. emit1(0x88 + reg + ind);
  90. emit1(exp.val);
  91. } else {
  92. emit1(0x89 + reg + ind);
  93. #ifdef RELOCATION
  94. if (rflag != 0 && PASS_RELO)
  95. newrelo(exp.typ, RELO2|RELBR);
  96. #endif
  97. emit2(exp.val);
  98. }
  99. }