Example #1
0
int_list dec_to_bin2(int n){
  int_list EBX;
  int quotient, remainder;
  if(n ==0) EAX = NULL;//empty list
  else 
  { //quotient = n/2; //or shift right one bit
    quotient = n >> 1;
    dec_to_bin2(quotient);
    EBX = EAX;
    remainder = n%2; // or shift right and check carry flag
    cons2(remainder, NULL); //returns result in EAX
    append2(EBX, EAX);     //returns result in EAX
  }
}
Example #2
0
Node *cons2(Loc *loc, int what, Node *left, Node *right)
{
	if (!left || !right) {
		rm(loc, right);
		rm(loc, left);
		return 0;
	} else if (what == nSEMI && left->what == nSEMI) {
		/* Build a list */
		Node *n;
		for (n = left; n->r && n->r->what == nSEMI; n = n->r);
		n->r = cons2(loc, nSEMI, n->r, right);
		return left;
	} else {
		Node *n = al_item(loc->free_list);
		n->what = what;
		n->l = left;
		n->r = right;
		n->s = 0;
		*n->loc = *loc;
		return n;
	}
}