1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- /*****************************************************************************/
- /* */
- /* ASM (B322 Assembler) */
- /* */
- /* Assembler for B322 */
- /* Contains all pass 2 functions */
- /* */
- /*****************************************************************************/
- word getNumberForLabel(char* labelName)
- {
- word bdosOffset = USERBDOS_OFFSET;
- word i;
- for (i = 0; i < labelListIndex; i++)
- {
- if (strcmp(labelName, labelListName[i]) == 0)
- {
- return (labelListLineNumber[i] + bdosOffset);
- }
- }
- BDOS_PrintConsole("Could not find label: ");
- BDOS_PrintConsole(labelName);
- BDOS_PrintConsole("\n");
- exit(1);
- return 0;
- }
- // Convert a 32 bit word into an array of 4 bytes
- void instrToByteArray(word instr, char* byteArray)
- {
- byteArray[0] = ((unsigned)instr >> 24) & 0xFF;
- byteArray[1] = ((unsigned)instr >> 16) & 0xFF;
- byteArray[2] = ((unsigned)instr >> 8) & 0xFF;
- byteArray[3] = instr & 0xFF;
- }
- void pass2Halt(char* outputAddr, char* outputCursor)
- {
- char instr[4] = {0xff, 0xff, 0xff, 0xff};
- memcpy((outputAddr + *outputCursor), instr, 4);
- (*outputCursor) += 4;
- }
- void pass2Read(char* outputAddr, char* outputCursor)
- {
- word instr = 0xE0000000;
- word arg1num = getNumberAtArg(1);
- word negative = 0;
- if (arg1num < 0)
- {
- negative = 1;
- arg1num = -arg1num;
- }
- // arg1 should fit in 16 bits
- if (((unsigned)arg1num >> 16) > 0)
- {
- BDOS_PrintConsole("READ: arg1 is >16 bits\n");
- exit(1);
- }
- instr += (arg1num << 12);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("READ: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 8);
- // arg3
- char arg3buf[16];
- getArgPos(3, arg3buf);
- // arg3 should be a reg
- if (arg3buf[0] != 'r')
- {
- BDOS_PrintConsole("READ: arg3 not a reg\n");
- exit(1);
- }
- word arg3num = strToInt(&arg3buf[1]);
- instr += arg3num;
- if (negative)
- {
- instr ^= (1 << 5);
- }
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Write(char* outputAddr, char* outputCursor)
- {
- word instr = 0xD0000000;
- word arg1num = getNumberAtArg(1);
- word negative = 0;
- if (arg1num < 0)
- {
- negative = 1;
- arg1num = -arg1num;
- }
- // arg1 should fit in 16 bits
- if (((unsigned)arg1num >> 16) > 0)
- {
- BDOS_PrintConsole("WRITE: arg1 is >16 bits\n");
- exit(1);
- }
- instr += (arg1num << 12);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("WRITE: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 8);
- // arg3
- char arg3buf[16];
- getArgPos(3, arg3buf);
- // arg3 should be a reg
- if (arg3buf[0] != 'r')
- {
- BDOS_PrintConsole("WRITE: arg3 not a reg\n");
- exit(1);
- }
- word arg3num = strToInt(&arg3buf[1]);
- instr += (arg3num << 4);
- if (negative)
- {
- instr ^= 1;
- }
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Readintid(char* outputAddr, char* outputCursor)
- {
- word instr = 0xC0000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("READINTID: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += arg1num;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Push(char* outputAddr, char* outputCursor)
- {
- word instr = 0xB0000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("PUSH: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 4);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Pop(char* outputAddr, char* outputCursor)
- {
- word instr = 0xA0000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("POP: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += arg1num;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Jump(char* outputAddr, char* outputCursor)
- {
- word instr = 0x90000000;
-
- // check if jump to label
- // if yes, replace label with line number
- char arg1buf[LABEL_NAME_SIZE+1];
- getArgPos(1, arg1buf);
- word arg1bufLen = strlen(arg1buf);
- word argIsLabel = 0;
- word i;
- for (i = 0; i < arg1bufLen; i++)
- {
- if (arg1buf[i] < '0' || arg1buf[i] > '9')
- {
- argIsLabel = 1;
- break;
- }
- }
- word arg1num = 0;
- if (argIsLabel)
- {
- arg1num = getNumberForLabel(arg1buf);
- }
- else
- {
- arg1num = getNumberAtArg(1);
- }
- // arg1 should fit in 27 bits
- if (((unsigned)arg1num >> 27) > 0)
- {
- BDOS_PrintConsole("JUMPO: arg1 is >27 bits\n");
- exit(1);
- }
- instr += (arg1num << 1);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Jumpo(char* outputAddr, char* outputCursor)
- {
- word instr = 0x90000000;
- word arg1num = getNumberAtArg(1);
- // arg1 should fit in 27 bits
- if (((unsigned)arg1num >> 27) > 0)
- {
- BDOS_PrintConsole("JUMPO: arg1 is >27 bits\n");
- exit(1);
- }
- instr += (arg1num << 1);
- instr ^= 1;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Jumpr(char* outputAddr, char* outputCursor)
- {
- word instr = 0x80000000;
- word arg1num = getNumberAtArg(1);
- // arg1 should fit in 16 bits
- if (((unsigned)arg1num >> 16) > 0)
- {
- BDOS_PrintConsole("JUMPR: arg1 is >16 bits\n");
- exit(1);
- }
- instr += (arg1num << 12);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("JUMPR: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Jumpro(char* outputAddr, char* outputCursor)
- {
- return;
- }
- void pass2Beq(char* outputAddr, char* outputCursor)
- {
- word instr = 0x60000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("BEQ: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 8);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("BEQ: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- // arg3
- word arg3num = getNumberAtArg(3);
- // arg3 should fit in 16 bits
- if (((unsigned)arg3num >> 16) > 0)
- {
- BDOS_PrintConsole("BEQ: arg3 is >16 bits\n");
- exit(1);
- }
- instr += (arg3num << 12);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Bgt(char* outputAddr, char* outputCursor)
- {
- word instr = 0x40000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("BGT: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 8);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("BGT: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- // arg3
- word arg3num = getNumberAtArg(3);
- // arg3 should fit in 16 bits
- if (((unsigned)arg3num >> 16) > 0)
- {
- BDOS_PrintConsole("BGT: arg3 is >16 bits\n");
- exit(1);
- }
- instr += (arg3num << 12);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Bgts(char* outputAddr, char* outputCursor)
- {
- word instr = 0x40000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("BGTS: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 8);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("BGTS: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- // arg3
- word arg3num = getNumberAtArg(3);
- // arg3 should fit in 16 bits
- if (((unsigned)arg3num >> 16) > 0)
- {
- BDOS_PrintConsole("BGTS: arg3 is >16 bits\n");
- exit(1);
- }
- instr += (arg3num << 12);
- instr ^= 1;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Bge(char* outputAddr, char* outputCursor)
- {
- word instr = 0x30000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("BGE: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 8);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("BGE: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- // arg3
- word arg3num = getNumberAtArg(3);
- // arg3 should fit in 16 bits
- if (((unsigned)arg3num >> 16) > 0)
- {
- BDOS_PrintConsole("BGE: arg3 is >16 bits\n");
- exit(1);
- }
- instr += (arg3num << 12);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Bges(char* outputAddr, char* outputCursor)
- {
- word instr = 0x30000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("BGES: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 8);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("BGES: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- // arg3
- word arg3num = getNumberAtArg(3);
- // arg3 should fit in 16 bits
- if (((unsigned)arg3num >> 16) > 0)
- {
- BDOS_PrintConsole("BGES: arg3 is >16 bits\n");
- exit(1);
- }
- instr += (arg3num << 12);
- instr ^= 1;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Bne(char* outputAddr, char* outputCursor)
- {
- word instr = 0x50000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("BNE: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 8);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("BNE: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- // arg3
- word arg3num = getNumberAtArg(3);
- // arg3 should fit in 16 bits
- if (((unsigned)arg3num >> 16) > 0)
- {
- BDOS_PrintConsole("BNE: arg3 is >16 bits\n");
- exit(1);
- }
- instr += (arg3num << 12);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Blt(char* outputAddr, char* outputCursor)
- {
- return;
- }
- void pass2Blts(char* outputAddr, char* outputCursor)
- {
- return;
- }
- void pass2Ble(char* outputAddr, char* outputCursor)
- {
- return;
- }
- void pass2Bles(char* outputAddr, char* outputCursor)
- {
- return;
- }
- void pass2Savpc(char* outputAddr, char* outputCursor)
- {
- word instr = 0x20000000;
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("SAVPC: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += arg1num;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Reti(char* outputAddr, char* outputCursor)
- {
- char instr[4] = {0x10, 0x00, 0x00, 0x00};
- memcpy((outputAddr + *outputCursor), instr, 4);
- (*outputCursor) += 4;
- }
- void pass2ArithBase(char* outputAddr, char* outputCursor, word arithOpCode)
- {
- word instr = 0;
- instr += (arithOpCode << 23);
- // arg1
- char arg1buf[16];
- getArgPos(1, arg1buf);
- // arg1 should be a reg
- if (arg1buf[0] != 'r')
- {
- BDOS_PrintConsole("ARITH: arg1 not a reg\n");
- exit(1);
- }
- word arg1num = strToInt(&arg1buf[1]);
- instr += (arg1num << 8);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- word arg2num = 0;
- // if arg2 is a const
- if (arg2buf[0] != 'r')
- {
- arg2num= getNumberAtArg(2);
- // arg1 should fit in 11 bits
- if (((unsigned)arg2num >> 11) > 0)
- {
- BDOS_PrintConsole("ARITH: const is >11 bits\n");
- exit(1);
- }
- instr += (arg2num << 12);
- instr ^= (1 << 27); // set constant bit
- }
- else // arg2 is a reg
- {
- arg2num = strToInt(&arg2buf[1]);
- instr += (arg2num << 4);
- }
- // arg3
- char arg3buf[16];
- getArgPos(3, arg3buf);
- // arg3 should be a reg
- if (arg3buf[0] != 'r')
- {
- BDOS_PrintConsole("ARITH: arg3 not a reg\n");
- exit(1);
- }
- word arg3num = strToInt(&arg3buf[1]);
- instr += arg3num;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Or(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x0);
- }
- void pass2And(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x1);
- }
- void pass2Xor(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x2);
- }
- void pass2Add(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x3);
- }
- void pass2Sub(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x4);
- }
- void pass2Shiftl(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x5);
- }
- void pass2Shiftr(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x6);
- }
- void pass2Shiftrs(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x0);
- }
- void pass2Mults(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x7);
- }
- void pass2Multu(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x7);
- }
- void pass2Slt(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x7);
- }
- void pass2Sltu(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x7);
- }
- void pass2Not(char* outputAddr, char* outputCursor)
- {
- pass2ArithBase(outputAddr, outputCursor, 0x8);
- }
- void pass2Load(char* outputAddr, char* outputCursor)
- {
- word instr = 0x70000000;
- word arg1num = getNumberAtArg(1);
- // arg1 should fit in 16 bits
- if (((unsigned)arg1num >> 16) > 0)
- {
- BDOS_PrintConsole("LOAD: arg1 is >16 bits\n");
- exit(1);
- }
- instr += (arg1num << 12);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("LOAD: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += arg2num;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Loadhi(char* outputAddr, char* outputCursor)
- {
- word instr = 0x70000000;
- word arg1num = getNumberAtArg(1);
- // arg1 should fit in 16 bits
- if (((unsigned)arg1num >> 16) > 0)
- {
- BDOS_PrintConsole("LOADHI: arg1 is >16 bits\n");
- exit(1);
- }
- instr += (arg1num << 12);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("LOADHI: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += arg2num;
- instr ^= (1 << 8);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2LoadLabelLow(char* outputAddr, char* outputCursor)
- {
- word instr = 0x70000000;
- char arg1buf[LABEL_NAME_SIZE+1];
- getArgPos(1, arg1buf);
- word arg1num = getNumberForLabel(arg1buf);
- // only use the lowest 16 bits
- arg1num = arg1num << 16;
- arg1num = (unsigned)arg1num >> 16;
- instr += (arg1num << 12);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("LOADLABELLOW: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += arg2num;
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2LoadLabelHigh(char* outputAddr, char* outputCursor)
- {
- word instr = 0x70000000;
- char arg1buf[LABEL_NAME_SIZE+1];
- getArgPos(1, arg1buf);
- word arg1num = getNumberForLabel(arg1buf);
- // only use the highest 16 bits
- arg1num = (unsigned)arg1num >> 16;
- instr += (arg1num << 12);
- // arg2
- char arg2buf[16];
- getArgPos(2, arg2buf);
- // arg2 should be a reg
- if (arg2buf[0] != 'r')
- {
- BDOS_PrintConsole("LOADLABELHIGH: arg2 not a reg\n");
- exit(1);
- }
- word arg2num = strToInt(&arg2buf[1]);
- instr += arg2num;
- instr ^= (1 << 8);
- // write to mem
- char byteInstr[4];
- instrToByteArray(instr, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Nop(char* outputAddr, char* outputCursor)
- {
- char instr[4] = {0x00, 0x00, 0x00, 0x00};
- memcpy((outputAddr + *outputCursor), instr, 4);
- (*outputCursor) += 4;
- }
- void pass2Dw(char* outputAddr, char* outputCursor)
- {
- word dwValue = getNumberAtArg(1);
- // write to mem
- char byteInstr[4];
- instrToByteArray(dwValue, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
- void pass2Dl(char* outputAddr, char* outputCursor)
- {
- char arg1buf[LABEL_NAME_SIZE+1];
- getArgPos(1, arg1buf);
- word dlValue = getNumberForLabel(arg1buf);
- // write to mem
- char byteInstr[4];
- instrToByteArray(dlValue, byteInstr);
- memcpy((outputAddr + *outputCursor), byteInstr, 4);
- (*outputCursor) += 4;
- }
|