Operands.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*------------------------------------------------------------------*/
  2. /* */
  3. /* MC68000 Cross Assembler */
  4. /* */
  5. /* Copyright 1985 by Brian R. Anderson */
  6. /* */
  7. /* Operand processor - April 16, 1991 */
  8. /* */
  9. /* This program may be copied for personal, non-commercial use */
  10. /* only, provided that the above copyright notice is included */
  11. /* on all copies of the source code. Copying for any other use */
  12. /* without the consent of the author is prohibited. */
  13. /* */
  14. /*------------------------------------------------------------------*/
  15. /* */
  16. /* Originally published (in Modula-2) in */
  17. /* Dr. Dobb's Journal, April, May, and June 1986. */
  18. /* */
  19. /* AmigaDOS conversion copyright 1991 by Charlie Gibbs. */
  20. /* */
  21. /*------------------------------------------------------------------*/
  22. #include "A68kdef.h"
  23. #include "A68kglb.h"
  24. int GetArgs (name) char *name;
  25. /* Gets macro arguments and adds them to FNStack after adding "name".
  26. Returns the number of arguments added to the stack.
  27. Note that this might not be the full number of arguments
  28. provided if the stack overflowed. */
  29. {
  30. register char *s, *t;
  31. int narg, instring;
  32. int instring2,instring3; /* bugfix by Kevin Kofler for the TIGCC team in v.2.71.F3b */
  33. char currarg[MAXLINE]; /* Current argument */
  34. narg = strlen (name) + 1;
  35. Heap2Space (narg); /* Find space for name. */
  36. strcpy (NextFNS, name); /* Add name to stack. */
  37. NextFNS += narg; /* Bump pointer. */
  38. if (NextFNS > High2)
  39. High2 = NextFNS; /* Update the high-water mark. */
  40. narg = 0; /* Argument counter */
  41. s = Line + SrcLoc; /* Now scan Line. */
  42. while (!isspace(*s) && (*s != ';') && (*s != '\0')) {
  43. t = currarg;
  44. if (instring = (*s == '<')) /* String delimiter */
  45. s++;
  46. /* bugfix by Kevin Kofler for the TIGCC team in v.2.71.F3b: */
  47. if ((instring2=(*s=='\''))||(instring3=(*s=='\"')))
  48. *t++ = *s++; /* Get a character. */
  49. while (1) {
  50. if (*s == '\0')
  51. break; /* End of line */
  52. if (instring) {
  53. if (*s == '>') {
  54. s++;
  55. break; /* End of string */
  56. }
  57. /* bugfix by Kevin Kofler for the TIGCC team in v.2.71.F3b:
  58. do not break up quoted strings! */
  59. } else if (instring2) {
  60. if (*s=='\'') {
  61. *t++ = *s++; /* Get a character. */
  62. if (*s!='\'') break;
  63. }
  64. } else if (instring3) {
  65. if (*s=='\"') {
  66. *t++ = *s++; /* Get a character. */
  67. if (*s!='\"') break;
  68. }
  69. } else {
  70. if ((*s == ',') /* End of operand */
  71. || isspace(*s) /* End of all operands */
  72. || (*s == ';')) /* Start of comments */
  73. break;
  74. }
  75. *t++ = *s++; /* Get a character. */
  76. }
  77. *t++ = '\0';
  78. Heap2Space (t - currarg); /* Check for space. */
  79. strcpy (NextFNS, currarg); /* Store argument. */
  80. NextFNS += t - currarg; /* Next available space */
  81. if (NextFNS > High2)
  82. High2 = NextFNS; /* High-water mark */
  83. narg++; /* Count arguments. */
  84. if (*s == ',')
  85. s++; /* Skip over separator. */
  86. }
  87. return (narg); /* Successful completion */
  88. }
  89. void EffAdr (EA, Bad) register struct OpConfig *EA; int Bad;
  90. /* Adds effective address field to Op (BITSET representing opcode). */
  91. {
  92. if ((1 << (EA->Mode - 1)) IN Bad) {
  93. Error (EA->Loc, ModeErr); /* Invalid mode */
  94. return;
  95. } else if (EA->Mode > 12) /* Special modes */
  96. return;
  97. else if (EA->Mode < 8) /* Register direct or indirect */
  98. Op |= ((EA->Mode - 1) << 3) | EA->Rn;
  99. else
  100. Op |= 0x0038 | (EA->Mode - 8); /* Absolute modes */
  101. OperExt (EA);
  102. }
  103. void OperExt (EA) register struct OpConfig *EA;
  104. /* Calculate operand Extension word, and check range of operands. */
  105. {
  106. switch (EA->Mode) {
  107. case AbsL:
  108. break; /* No range checking is needed. */
  109. case AbsW:
  110. case ARDisp:
  111. case PCDisp:
  112. /* In all-reloc mode, we need to compute the distance here.
  113. -- Kevin Kofler, v.2.71.F3o */
  114. if ((EA->Mode == PCDisp && AllRelocs && EA->Hunk == CurrHunk) ?
  115. ((EA->Value-AddrCnt-EA->PCConv < -32768)
  116. || (EA->Value-AddrCnt-EA->PCConv > 32767)) :
  117. ((EA->Value < -32768) || (EA->Value > 32767)))
  118. /* if ((EA->Value < -32768) || (EA->Value > 32767)) */
  119. Error (EA->Loc, SizeErr);
  120. break;
  121. case ARDisX:
  122. case PCDisX:
  123. /* In all-reloc mode, we need to compute the distance here.
  124. -- Kevin Kofler, v.2.71.F3o */
  125. if ((EA->Mode == PCDisX && AllRelocs && EA->Hunk == CurrHunk) ?
  126. ((EA->Value-AddrCnt-EA->PCConv < -128)
  127. || (EA->Value-AddrCnt-EA->PCConv > 127)) :
  128. ((EA->Value < -128) || (EA->Value > 127)))
  129. /* if ((EA->Value < -128) || (EA->Value > 127)) */
  130. Error (EA->Loc, SizeErr);
  131. EA->Value &= 0x00FF; /* Displacement */
  132. EA->Value |= EA->Xn << 12; /* Index reg. */
  133. if (EA->X == Areg) EA->Value |= 0x8000; /* Addr. Reg. */
  134. if (EA->Xsize == Long) EA->Value |= 0x0800; /* Long reg. */
  135. break;
  136. case Imm:
  137. if (Size == Word) {
  138. if ((EA->Value < -32768) || (EA->Value > 65535L))
  139. Error (EA->Loc, SizeErr);
  140. } else if (Size == Byte)
  141. if ((EA->Value < -128) || (EA->Value > 255))
  142. Error (EA->Loc, SizeErr);
  143. break;
  144. }
  145. }
  146. void GetOperand (oper, op, pcconv)
  147. char *oper; register struct OpConfig *op; int pcconv;
  148. /* Finds mode and value for source or destination operand.
  149. If PC-relative addressing is permitted, "pcconv" gives the
  150. offset to the displacement word; otherwise "pcconv" is zero. */
  151. {
  152. register char *s, *t;
  153. register int i;
  154. char *opend;
  155. char UCoper[MAXLINE], tempop[MAXLINE];
  156. int rloc;
  157. long templong;
  158. op->Value = op->Defn = 0;
  159. op->Mode = Null;
  160. op->X = X0;
  161. op->Hunk = ABSHUNK;
  162. op->Single = FALSE;
  163. op->Unopt = FALSE; /* initialize Unopt field -- Kevin Kofler, v.2.71.F3t */
  164. if (*oper == '\0')
  165. return; /* There is nothing to process. */
  166. s = oper;
  167. t = UCoper;
  168. while (*s) {
  169. *t++ = /*toupper*/ (*s); /* Upper-case version */
  170. s++;
  171. }
  172. *t = '\0';
  173. opend = s - 1; /* Last character of operand */
  174. if (*oper == '#') { /* Immediate */
  175. s = oper + 1; /* The value starts here. */
  176. if (*s == '~')
  177. s++; /* Skip over unary NOT. */
  178. op->Value = GetValue (s, (op->Loc)+1);
  179. op->Mode = Imm;
  180. op->Hunk = Hunk2;
  181. op->Defn = DefLine2;
  182. op->Single = SingleFlag;
  183. if (*(oper+1) == '~') { /* Unary NOT of entire value */
  184. if (Hunk2 != ABSHUNK
  185. || AddrDiffs /* added by Kevin Kofler in v.2.71.F3l */
  186. ) {
  187. Error (op->Loc + 2, RelErr);
  188. op->Hunk = ABSHUNK; /* Must be absolute! */
  189. }
  190. op->Value = ~(op->Value); /* Flip all bits. */
  191. if (Size == Byte)
  192. op->Value &= 0xFFL; /* Trim to 8 bits. */
  193. else if (Size == Word)
  194. op->Value &= 0xFFFFL; /* Trim to 16 bits. */
  195. }
  196. return;
  197. }
  198. i = IsRegister (oper, opend-oper+1);
  199. if (i >= 0) {
  200. op->Mode = (i & 8) ? ARDir : DReg; /* Register type */
  201. op->Rn = i & 7; /* Register number */
  202. return;
  203. } else if (i == -2) {
  204. op->Mode = MultiM; /* Equated register list */
  205. op->Value = Sym->Val;
  206. return;
  207. } else if ((*oper == '(') && (*opend == ')')) {
  208. i = IsRegister (oper+1, opend-oper-1);
  209. if (i >= 8 && i <= 15) {
  210. op->Mode = ARInd; /* Address Register indirect */
  211. op->Rn = i - 8;
  212. return;
  213. } else if (i != -1) {
  214. Error (op->Loc, AddrErr); /* Data register is invalid! */
  215. return;
  216. } /* else may be parenthesized expression */
  217. } else if ((*oper == '(') /* Post-increment */
  218. && (*opend == '+')
  219. && (*(opend-1) == ')')) {
  220. op->Mode = ARPost;
  221. op->Rn = GetAReg (oper+1, opend-oper-2, op->Loc + 1);
  222. return;
  223. } else if ((*oper == '-') /* Pre-decrement */
  224. && (*opend == ')')
  225. && (*(oper+1) == '(')) {
  226. i = IsRegister (oper+2, opend-oper-2);
  227. if (i >= 8 && i <= 15) {
  228. op->Mode = ARPre;
  229. op->Rn = i - 8;
  230. return;
  231. } else if (i > 0) {
  232. Error (op->Loc, AddrErr); /* Data register is invalid! */
  233. return;
  234. } /* else parenthesized expression with leading minus? */
  235. } else if (strcasecmp (UCoper, "SR") == 0) {
  236. op->Mode = SR; /* Status Register */
  237. return;
  238. } else if (strcasecmp (UCoper, "CCR") == 0) {
  239. op->Mode = CCR; /* Condition Code Register */
  240. return;
  241. } else if (strcasecmp (UCoper, "USP") == 0) {
  242. op->Mode = USP; /* User Stack Pointer */
  243. return;
  244. }
  245. /* Try to split off displacement (if present).
  246. We'll assume we have a register expression if the operand
  247. ends with a parenthesized expression not preceded by an
  248. operator. I know this code is a real kludge, but that's
  249. the result of the bloody syntax. Thanks, Motorola. */
  250. s = opend; /* Last character */
  251. if (i = (*s == ')')) /* Trailing parenthesis? */
  252. while (*(--s) != '(') /* Find left parenthesis. */
  253. if (s <= oper)
  254. break;
  255. if (s <= oper) /* Must not be at beginning. */
  256. i = FALSE;
  257. if (i) {
  258. if (s == (oper+1)) {
  259. if (*oper == '-')
  260. i = FALSE; /* Leading minus sign */
  261. } else {
  262. t = s - 1;
  263. if (*t == '*') { /* Location counter? */
  264. t--;
  265. if (!IsOperator (t) || (*t == ')'))
  266. i = FALSE; /* No, it's multiplication. */
  267. } else if (IsOperator (t) && (*t != ')')) {
  268. i = FALSE; /* Preceded by an operator */
  269. }
  270. }
  271. }
  272. if (i) { /* Looks like a displacement mode */
  273. *s = '\0';
  274. op->Value = GetValue (oper, op->Loc); /* Displacement */
  275. op->Hunk = Hunk2; /* Hunk number */
  276. op->Defn = DefLine2; /* Line where defined */
  277. *s++ = '('; /* Restore parenthesis. */
  278. rloc = op->Loc + s - oper; /* The register starts here. */
  279. s = GetField (s, tempop); /* Get address register. */
  280. if (*s == '\0') /* If there's no index register, */
  281. tempop[strlen(tempop)-1] = '\0'; /* chop off parenthesis. */
  282. if ((tempop[2] == '\0')
  283. && (toupper (tempop[0]) == 'P')
  284. && (toupper (tempop[1]) == 'C')) {
  285. op->Mode = PCDisp; /* Program Counter */
  286. op->PCConv = pcconv; /* added by Kevin Kofler in v.2.71.F3o */
  287. if (op->Hunk == CurrHunk) {
  288. if (!AllRelocs) { /* Do not adjust displacement when outputting all
  289. relocs. -- Kevin Kofler, v.2.71.F3l
  290. But don't return immediately. -- Kevin Kofler, v.2.71.F3m */
  291. op->Value -= (AddrCnt+pcconv); /* Adjust displacement. */
  292. op->Hunk = ABSHUNK; }
  293. }
  294. } else {
  295. if ((op->Value == 0) /* If displacement is zero */
  296. && (op->Hunk == ABSHUNK) /* and is absolute */
  297. && (op->Defn < LineCount) /* and is already defined */
  298. && !(OpM68R IN AdrModeA) /* and isn't for a MOVEP */
  299. && !AddrDiffs /* and we don't have address differences to emit
  300. -- Kevin Kofler, v.2.71.F3q */
  301. && !NoOpt) /* and we can optimize */
  302. op->Mode = ARInd; /* forget the displacement. */
  303. else
  304. op->Mode = ARDisp; /* Address reg. w/displacement */
  305. op->Rn = GetAReg (tempop, strlen (tempop), rloc);
  306. }
  307. if (*s != '\0') { /* Index register is present. */
  308. if (op->Mode == PCDisp)
  309. op->Mode = PCDisX; /* Program Counter indexed */
  310. else
  311. op->Mode = ARDisX; /* Address Register indexed */
  312. if (*s != ',')
  313. Error (op->Loc, AddrErr); /* Bad separator */
  314. s++; /* Skip separator. */
  315. rloc = op->Loc + s - oper; /* Start of index */
  316. s = GetField (s, tempop); /* Get index register. */
  317. t = tempop + strlen(tempop);
  318. if (*s == '\0')
  319. *(--t) = '\0'; /* Chop parenthesis. */
  320. else
  321. Error (rloc, AddrErr); /* It better be there. */
  322. t -= 2;
  323. if ((t < tempop) || (*t != '.')) {
  324. op->Xsize = Word; /* Size defaults to 16 bits. */
  325. t += 3;
  326. } else {
  327. *t++ = '\0'; /* Chop off size code. */
  328. switch (toupper (*t)) {
  329. case 'W': /* Word */
  330. op->Xsize = Word;
  331. break;
  332. case 'L': /* Long */
  333. op->Xsize = Long;
  334. break;
  335. default:
  336. Error (op->Loc+s-1-oper, SizeErr); /* Invalid size */
  337. op->Xsize = Word; /* Make it word for now. */
  338. }
  339. }
  340. i = IsRegister (tempop,t-tempop-1); /* Get register. */
  341. op->Xn = i & 7; /* Index register number */
  342. if ((i >= 0) && (i <= 7))
  343. op->X = Dreg; /* Data Register */
  344. else if ((i >= 8) && (i <= 15))
  345. op->X = Areg; /* Address Register */
  346. else
  347. Error (rloc, AddrErr); /* Invalid register */
  348. }
  349. #if 0 /* Bugfix by Kevin Kofler (v.2.71.F3m): Removed this broken check
  350. because it does not make any sense and causes spurious error
  351. messages. */
  352. if ((op->Hunk >= 0) && (op->Hunk != ABSHUNK))
  353. Error (op->Loc, RelErr); /* Relocatable displacement */
  354. #endif
  355. /* Bugfix by Kevin Kofler (v.2.71.F3p): Handle the non-ABSHUNK-case correctly.*/
  356. /* if ((op->Mode == PCDisX) && (op->Hunk >= 0) && (op->Hunk != ABSHUNK))*/
  357. /* Bugfix by Kevin Kofler (v.2.71.F3r): Hunk may also be negative. */
  358. if ((op->Mode == PCDisX) && (op->Hunk != ABSHUNK))
  359. op->Value++;
  360. return;
  361. }
  362. if ((i = GetMultReg (oper, op->Loc)) != 0) {
  363. op->Value = (long) i;
  364. op->Mode = MultiM; /* Register list for MOVEM */
  365. return;
  366. }
  367. if ((*oper == '(') /* Operands of the form (xxxx).W or (xxxx).L */
  368. && (*(opend-2) == ')')
  369. && (*(opend-1) == '.')
  370. && ((toupper(*opend) == 'W') || (toupper(*opend) == 'L'))) {
  371. *(opend-1) = '\0'; /* Temporarily cut off length specifier. */
  372. op->Value = GetValue (oper, op->Loc); /* Get operand value. */
  373. op->Hunk = Hunk2;
  374. op->Defn = DefLine2;
  375. op->Single = SingleFlag;
  376. if (toupper(*opend) == 'W')
  377. op->Mode = AbsW; /* Absolute word */
  378. else
  379. {
  380. op->Mode = AbsL; /* Absolute long */
  381. /* Harcoded .l means the operand is unoptimizable. -- Kevin Kofler, v.2.71.F3t */
  382. op->Unopt = TRUE;
  383. }
  384. *(opend-1) = '.'; /* Restore original operand. */
  385. return;
  386. }
  387. op->Value = GetValue (oper, op->Loc); /* Plain old expression */
  388. op->Hunk = Hunk2;
  389. op->Defn = DefLine2;
  390. op->Single = SingleFlag;
  391. op->Mode = AbsL; /* Assume absolute long addressing. */
  392. if (NoOpt)
  393. return; /* Do no optimizing. */
  394. if (DefLine2 < LineCount) { /* Backward reference */
  395. if (Hunk2 < 0) {
  396. return; /* External - leave as absolute long. */
  397. } else if (Hunk2 == CurrHunk) { /* Reference to current hunk */
  398. if (pcconv) {
  399. templong = op->Value-(AddrCnt+pcconv); /* PC disp. */
  400. if ((templong >= -32768) && (templong <= 32767)) {
  401. op->Mode = PCDisp; /* Convert to PC relative mode. */
  402. op->PCConv = pcconv; /* added by Kevin Kofler in v.2.71.F3o */
  403. if (AllRelocs) return; /* Do not adjust displacement when outputting
  404. all relocs. -- Kevin Kofler, v.2.71.F3l */
  405. op->Value=templong; /* Adjust displacement. */
  406. op->Hunk = ABSHUNK;
  407. }
  408. }
  409. } else if (Hunk2 == ABSHUNK) { /* Absolute value */
  410. if ((op->Value >= -32768) && (op->Value <= 32767))
  411. op->Mode = AbsW; /* Absolute word */
  412. } else if ((SmallData != -1)
  413. && (op->Value>=0) && (op->Value<=65535L)) {
  414. op->Mode = ARDisp; /* Make it a data reference */
  415. op->Rn = SmallData; /* through specified register. */
  416. op->Value -= DataOffset; /* Adjust displacement. */
  417. op->Hunk = ABSHUNK;
  418. }
  419. return; /* Could default to absolute long. */
  420. } else if (SmallData==-1) { /* Fwd. reference - if not small data, */
  421. return; /* leave as absolute long addressing. */
  422. } else if (Brnch IN AdrModeA) {
  423. return; /* Branches are handled elsewhere. */
  424. } else if (!Pass2) { /* Forward reference, pass 1 */
  425. op->Mode = ARDisp; /* Assume displacement */
  426. op->Rn = SmallData; /* from specified register. */
  427. op->Hunk = ABSHUNK;
  428. return;
  429. } else { /* On pass 2 we know what it is. */
  430. if (Hunk2 < 0) {
  431. Error (op->Loc,FwdRef); /* External - must be 32 bits. */
  432. op->Mode = AbsW; /* Force absolute word anyway. */
  433. } else if (Hunk2 == CurrHunk) { /* It's in the current hunk. */
  434. op->Mode = PCDisp; /* Convert to PC relative mode. */
  435. op->Value -= AddrCnt + pcconv; /* Adjust displacement. */
  436. op->Hunk = ABSHUNK;
  437. if (!pcconv || (op->Value < -32768) || (op->Value > 32767))
  438. Error (op->Loc,FwdRef); /* It doesn't fit! */
  439. } else if (Hunk2 == ABSHUNK) { /* It's absolute. */
  440. op->Mode = AbsW; /* It has to fit in a word. */
  441. if ((op->Value < -32768) || (op->Value > 32767))
  442. Error (op->Loc,FwdRef); /* It doesn't fit! */
  443. } else {
  444. op->Mode = ARDisp; /* Assume data reference */
  445. op->Rn = SmallData; /* through specified register. */
  446. op->Value -= DataOffset; /* Adjust displacement. */
  447. if ((op->Value < -32768) || (op->Value > 32767))
  448. Error (op->Loc,FwdRef); /* It doesn't fit! */
  449. }
  450. }
  451. }
  452. int GetMultReg (oper, loc) char *oper; int loc;
  453. /* Builds a register mask for the MOVEM instruction.
  454. Returns the mask in the low-order portion of its value if
  455. "oper" is a valid multiple-register list; otherwise returns 0. */
  456. {
  457. register char *s, *t;
  458. register int j;
  459. int t1, t2; /* Temporary variables for registers */
  460. int range; /* We're processing a range of registers. */
  461. int multext; /* The result is built here. */
  462. multext = 0;
  463. range = FALSE;
  464. s = oper;
  465. if (IsOperator (s))
  466. return (0); /* Starts with an operator! */
  467. while (1) {
  468. for (t = s; *t; t++) {
  469. if ((*t == '-') || (*t == '/')) {
  470. break;
  471. }
  472. }
  473. if ((multext == 0) && (*t == '\0'))
  474. return (0); /* Reject single term. */
  475. if ((t2 = IsRegister (s, (int)(t-s))) < 0)
  476. return (0); /* Not a recognizable register */
  477. if (!range) {
  478. multext |= (1 << t2); /* Single register */
  479. t1 = t2; /* Save number in case it's a range. */
  480. } else { /* Range of registers */
  481. range = FALSE;
  482. if (t1 > t2) {
  483. j = t1; /* Swap registers if backwards. */
  484. t1 = t2;
  485. t2 = j;
  486. }
  487. for (j = t1; j <= t2; j++)
  488. multext |= (1 << j); /* Mark all registers in range. */
  489. if (*t == '-')
  490. return (0); /* Invalid range */
  491. }
  492. if (*t == '\0')
  493. break; /* Normal end of operand */
  494. if (*t++ == '-')
  495. range = TRUE; /* Range indicator */
  496. if (*t == '\0')
  497. return (0); /* Premature end of operand */
  498. s = t;
  499. }
  500. return (multext);
  501. }
  502. int GetAReg (op, len, loc) char *op; int len, loc;
  503. /* Validate an address register specification.
  504. Valid specifications are A0 through A7, SP, or an EQUR label.
  505. The address register number will be returned if it is valid.
  506. Otherwise, Error will be called, using "loc" for the error
  507. location (this is its only use), and zero (A0) will be returned. */
  508. {
  509. register int i;
  510. i = IsRegister (op, len); /* Get register number. */
  511. if ((i >= 8) && (i <= 15))
  512. return (i - 8); /* Valid address register */
  513. else {
  514. Error (loc, AddrErr); /* Not an address register */
  515. return (0); /* Set to A0. */
  516. }
  517. }
  518. int IsRegister (op, len) char *op; int len;
  519. /* Check whether the current operand is an address or data register.
  520. Valid specifications are D0 through D7, A0 through A7, SP,
  521. or any symbol equated to a register with the EQUR directive.
  522. Return values:
  523. 0 through 7 - data registers 0 through 7 respectively
  524. 8 through 15 - address registers 0 through 7 respectively
  525. -1 - not a recognizable register
  526. -2 - Equated register list for MOVEM instruction (REG) */
  527. {
  528. char tempop[MAXLINE];
  529. register char *s;
  530. register int i;
  531. if (len == 2) { /* Two-character specification */
  532. i = toupper (*op);
  533. s = op + 1;
  534. if ((i == 'S') && (toupper (*s) == 'P')) {
  535. return (15); /* Stack Pointer */
  536. } else if ((*s >= '0') && (*s <= '7')) {
  537. if (i == 'A') {
  538. return (*s - '0' + 8); /* Address Register */
  539. } else if (i == 'D') {
  540. return (*s - '0'); /* Data Register */
  541. }
  542. }
  543. }
  544. if (!GotEqur) /* If we have no EQURs to check */
  545. return (-1); /* don't waste any time here. */
  546. for (i = 0, s = op; i < len; i++) {
  547. if (IsOperator (s))
  548. return (-1); /* It sure isn't a label. */
  549. tempop[i] = *s++;
  550. }
  551. tempop[i] = '\0';
  552. if (ReadSymTab (tempop)) {
  553. if (Sym->Flags & 0x60) {
  554. AddRef (LineCount); /* Found a register or list. */
  555. return ((Sym->Flags & 0x20) ? (int) Sym->Val : -2);
  556. }
  557. }
  558. return (-1); /* Not a recognizable register */
  559. }
  560. int GetInstModeSize (Mode) register int Mode;
  561. /* Determines the size for the various instruction modes. */
  562. {
  563. switch (Mode) {
  564. case ARDisp:
  565. case ARDisX:
  566. case PCDisp:
  567. case PCDisX:
  568. case AbsW:
  569. return (2);
  570. case AbsL:
  571. return (4);
  572. case MultiM:
  573. return (0); /* Accounted for by code generator */
  574. case Imm:
  575. if (Size == Long)
  576. return (4);
  577. else
  578. return (2);
  579. default:
  580. return (0);
  581. }
  582. }