#include #include #include #include "assemble.h" void do_branch (long address, OperandType *operand, Label_Node *label_head, int pass, int line_no) { int label, i, hash; long reladdress; /* It's a branch instruction */ operand->addtype = REL; strcpy (operand->formatted, operand->orig); /* Work out it's value. either a number or a label */ if (operand->orig[0] == '#') { hash = 1; reladdress = get_value (operand, &operand->orig[1], label_head, pass, line_no); } else { hash = 0; reladdress = get_value (operand, operand->orig, label_head, pass, line_no); } label = 0; if (operand->orig[hash] != '$') if (operand->orig[hash] != '%') for (i=hash; iorig); i++) if (!isdigit(operand->orig[i])) label = 1; /* If it isn't a label use the value directly */ if (label == 0) operand->value = (char) reladdress; else /* If the label is recognised, use an offset value */ if (reladdress != 0x666666) operand->value = (reladdress - address - 2); else operand->value = 0x66; /* Is it a valid branch? */ if (operand->value > 127 || operand->value < -127) { fprintf (stderr, "Jump too large (%ld) at line /foo/. Make +/-127\n", operand->value); exit (EXIT_FAILURE); } else { operand->value = operand->value & 0xff; sprintf (operand->formatted, "$%2lX", operand->value); } }