#include "ccg"/* start of cc8 *//* start native assembly language */usr(adr)int adr;$(outbyte(0);outdec(adr);$)/* Fetch a static memory cell into the primary register */getmem(sym)char *sym;$(if((sym[ident]!=pointer)&(sym[type]==cchar))outbyte(1);else outbyte(2);outlab(sym);$)/* Fetch the address of the specified symbol *//*  into the primary register */getloc(sym)char *sym;$(outbyte(3);outdec((255&sym[offset])+((255&sym[offset+1])<<8)-oursp);$)/* Store the primary register into the specified *//* static memory cell */putmem(sym)char *sym;$(if((sym[ident]!=pointer)&(sym[type]==cchar))outbyte(4);else outbyte(5);outlab(sym+name);$)/* Store the specified object type in the primary register *//* at the address on the top of the stack */putstk(typeobj)char typeobj;$(if(typeobj==cchar)outbyte(6);else outbyte(7);popsp();$)/* Fetch the specified object type indirect through the *//* primary register into the primary register */indirect(typeobj)char typeobj;$(if(typeobj==cchar)outbyte(8);else outbyte(9);$)/* Swap the primary and secondary registers */swap()$(outbyte(10);$)/* Print partial instruction to get an immediate value *//* into the primary register */immed()$(outbyte(11);$)/* Push the primary register onto the stack */push()$(outbyte(12);pushsp();$)/* Swap the primary register and the top of the stack */swapstk()$(outbyte(14);$)/* Call the specified subroutine name */call(sname,narg)char *sname;int narg;$(outbyte(15);outlab(sname);outcch(narg+2); /* narg=2*# args */oursp=oursp-narg;$)/* Return from subroutine */ret()$(outbyte(16);$)/* Perform subroutine call to value on top of stack */callstk(narg)int narg;$(outbyte(17);outcch(narg+2);oursp=oursp-narg;popsp();$)/* Jump to specified internal label number */jump(label)int label;$(outbyte(18);outclb(label);$)/* * truejump -- jump to lable if p nz */truejump(label)int label;$(outbyte(13);outclb(label);$)/* * falsejump -- jump to lable if p z */falsejump(label)int label;$(outbyte(19);outclb(label);$)/* cmpjump -- compare p to constant * and jump not-equal to label */cmpjump(constant,label)int constant,label;$(outbyte(46);outdec(constant);outclb(label);$)/* Modify the stack pointer to the * new value indicated */modstk(newsp)int newsp; $(int k;k=newsp-oursp;if(k!=0)$(outbyte(20);outdec(k);$)return newsp;$)/* Double the primary register */doublereg()$(outbyte(21);$)/* Add the primary and secondary registers *//* (results in primary) */add()$(outbyte(22);popsp();$)/* Subtract the primary register from the secondary *//* (results in primary) */sub()$(outbyte(23);popsp();$)/* Multiply the primary and secondary registers *//* (results in primary */mult()$(outbyte(24);popsp();$)/* Divide the secondary register by the primary *//* (quotient in primary, remainder in secondary) */div()$(outbyte(25);popsp();$)/* Compute remainder (mod) of secondary register divided *//* by the primary *//* (remainder in primary, quotient in secondary) */mod()$(outbyte(26);popsp();$)/* Inclusive 'or' the primary and the secondary registers *//* (results in primary) */or()$(outbyte(27);popsp();$)/* Exclusive 'or' the primary and seconday registers *//* (results in primary) */xor()$(outbyte(28);popsp();$)/* 'And' the primary and secondary registers *//* (results in primary) */and()$(outbyte(29);popsp();$)/* Arithmetic shift right the secondary register number of *//* times in primary (results in primary) */asr()$(outbyte(30);popsp();$)/* Arithmetic left shift the secondary register number of *//* times in primary (results in primary) */asl()$(outbyte(31);popsp();$)/* Form two's complement of primary register */neg()$(outbyte(32);$)/* Form one's complement of primary register */com()$(outbyte(33);$)/* Increment the primary register by one */inc()$(outbyte(34);$)/* Decrement the primary register by one */dec()$(outbyte(35);$)/* Following are the conditional operators *//* They compare the secondary register against the primary *//* and put a literal 1 in the primary if the condition is *//* true, otherwise they clear the primary register *//* Test for equal */eq()$(outbyte(36);popsp();$)/* Test for not equal */ne()$(outbyte(37);popsp();$)/* Test for less than (signed) */lt()$(outbyte(38);popsp();$)/* Test for less than or equal to (signed) */le()$(outbyte(39);popsp();$)/* Test for greater than (signed) */gt()$(outbyte(40);popsp();$)/* Test for greater than or equal to (signed) */ge()$(outbyte(41);popsp();$)/* Test for less than (unsigned) */ult()$(outbyte(42);popsp();$)/* Test for less than or equal to (unsigned) */ule()$(outbyte(43);popsp();$)/* Test for greater than (unsigned) */ugt()$(outbyte(44);popsp();$)/* Test for greater than or equal to (unsigned) */uge()$(outbyte(45);popsp();$)outdec(numbr)int numbr;$(outbyte(131); /* 16 bit const */outbyte(numbr&255);outbyte((numbr>>8)&255);$)outcch(numbr)int numbr;$(outbyte(130); /* 8 bit const */outbyte(numbr&255);$)outlab(n) char *n;$(outclb(adtoi(n));$)outclb(sym)int sym;$(outbyte(128);outbyte(sym&255);outbyte((sym>>8)&255);$)outldf(n) char *n;$(outcdf(adtoi(n));$)outcdf(sym)int sym;$(outbyte(129);outbyte(sym&255);outbyte((sym>>8)&255);$)outdat(n)int n;$(outbyte(132);outbyte(n&255);outbyte((n>>8)&255);$)outslt(n)int n;$(outbyte(133);outbyte(n&255);outbyte((n>>8)&255);$)outsp(n)int n;$(outbyte(134);outbyte(n&255);outbyte((n>>8)&255);$)/* out a global or external name */outgoe(code,sname)char code,*sname;$(int adr;adr=adtoi(sname);outbyte(code);outbyte(adr&255);outbyte((adr>>8)&255);while(*sname)outbyte(*sname++);outbyte(0);$)adtoi(p)char *p;$(return (p-symtab)/symsiz+10000; /* offset */$)popsp()$(return oursp=oursp-2;$)pushsp()$(return oursp=oursp+2;$)/* End of cc8 */