int main()
{
   int n = 5;
   printint(recurfact(n));

   printint(iterfact(n));
}
Exemplo n.º 2
0
void semafor_down()
{
	int* shmem = get_mem();

	fore(getpid());
	print("Proceso 1 intenta bajar semaforo\n");

	sem_down();

	fore(getpid());
	print("Proceso 1 baja semaforo:\n");
	print("    Variable en shared memory tiene valor:\n");
	print("    ");
	printint(*shmem);
	*shmem = *shmem + 2;
	print("\n    Se le suma 2 y ahora tiene valor:\n");
	print("    ");
	printint(*shmem);
	print("\n");

	sleep(5);

	sem_up();
	fore(getpid());
	print("Proceso 1 levanta semaforo\n");

	fore(getppid());
	while(1);
}
Exemplo n.º 3
0
void main()
{
   int x;

   a[0] = 12;
   a[1] = 10;
   a[2] = 8;
   a[3] = 6;
   a[4] = 4;
   a[5] = 2;

   x = a[5];
   printint(x);    // 2
   printchar(10);

   printint(a[0]);  // 12
   printchar(10);

   printint(10+a[1]);  // 20
   printchar(10);

   x = a[2]*10 + a[3] + a[4];
   printint(x);  // should be 90
   printchar(10);

}
Exemplo n.º 4
0
Arquivo: slice.c Projeto: 8l/go-learn
// makeslice(nel int, cap int, width int) (ary []any);
void
runtime·makeslice(uint32 nel, uint32 cap, uint32 width, Slice ret)
{
	uint64 size;

	if(cap < nel)
		cap = nel;
	size = cap*width;

	ret.len = nel;
	ret.cap = cap;
	ret.array = mal(size);

	FLUSH(&ret);

	if(debug) {
		prints("makeslice: nel=");
		runtime·printint(nel);
		prints("; cap=");
		runtime·printint(cap);
		prints("; width=");
		runtime·printint(width);
		prints("; ret=");
		runtime·printslice(ret);
		prints("\n");
	}
}
Exemplo n.º 5
0
// slicecopy(to any, fr any, wid uint32) int
void
runtime·slicecopy(Slice to, Slice fm, uintptr width, int32 ret)
{
	if(fm.len == 0 || to.len == 0 || width == 0) {
		ret = 0;
		goto out;
	}

	ret = fm.len;
	if(to.len < ret)
		ret = to.len;

	if(ret == 1 && width == 1) {	// common case worth about 2x to do here
		*to.array = *fm.array;	// known to be a byte pointer
	} else {
		runtime·memmove(to.array, fm.array, ret*width);
	}

out:
	FLUSH(&ret);

	if(debug) {
		runtime·prints("main·copy: to=");
		runtime·printslice(to);
		runtime·prints("; fm=");
		runtime·printslice(fm);
		runtime·prints("; width=");
		runtime·printint(width);
		runtime·prints("; ret=");
		runtime·printint(ret);
		runtime·prints("\n");
	}
}
//printing function
void printint(int x) {
  if(x < 0) {
    putchar(45);
    x = -1*x;
    if (x == 0) {
      putchar(0);
    }
    else {
      int i = 0;
      i = x % 10 + 48;
      printint(x/10);
      putchar(i);
    }
  }
  else {
    if (x == 0) {
      putchar(0);
    }
    else {
      int i = 0;
      i = x % 10 + 48;
      printint(x/10);
      putchar(i);
    }
  }
}
Exemplo n.º 7
0
/*
*	Mesma função do printf no C. Recebe uma String e a posição a ser impresso
*	x e y; A string contem marcas que são substituidos pelos valores passados;
*	Possui suporte para:
*		%d Inteiro
*		%b Binário de um inteiro
*		%x Hexadecimal de um inteiro
*		%c Caracter
*		%s String
*		%% Valor de %
*		\n Quebra de linha
*		
*/
void print(const char *str,int x, int y,...){

	char *video = ((char *) VIDEO) + 160 * x + y;

	char *s;

	
	va_list va = (char*)(&y + 1);
	while(*str != 0){
		if(*str != '%'){
			
			if(*str == 0x0a){	// Quebra de linha "\n"
				int v = (int)(video - VIDEO);
				video+=160-(v-160*(v/160));
			}else{
	 	        	printc(*str,video);
			}			
			str++;
			


		}else {
		
			switch(*++str)
			{
				case 'd':
					video = printint(getInt(va),video,10);
					next_arg(va,int);
					break;
				case 'c':
					printc((char)*va,video);
					next_arg(va,int);
					break;
				case 'x':
					video = printint(getInt(va),video,16);
					next_arg(va,int);
					break;
				case 'b':
					video = printint(getInt(va),video,2);
					next_arg(va,int);
					break;
				case '%':
					printc('%',video);
					break;
				case 's':
					s = (char*) (getInt(va));
					while(*s != 0){
						printc((char)*s++,video);
					}
					next_arg(va,int);
					break;
				
			}
			
			str++;	
		}
	}
}
Exemplo n.º 8
0
// Print to the console. only understands %d, %x, %p, %s.
void
cprintf(char *fmt, ...)
{
  int i, c;
  int locking;
  uint *argp;
  char *s;

  locking = cons.locking;
  if(locking)
    acquire(&cons.lock);

  if (fmt == 0)
    panic("null fmt");

  argp = (uint *)(void*)(&fmt + 1);
  for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
    if(c != '%'){
    //    gpuputc(c);
	uartputc(c);
      continue;
    }
    c = fmt[++i] & 0xff;
    if(c == 0)
      break;
    switch(c){
    case 'd':
      printint(*argp++, 10, 1);
      break;
    case 'x':
    case 'p':
      printint(*argp++, 16, 0);
      break;
    case 's':
      if((s = (char*)*argp++) == 0)
        s = "(null)";
      for(; *s; s++){
      //  gpuputc(*s);
	uartputc(*s);
      }
      break;
    case '%':
//	gpuputc('%');
	uartputc('%');
      break;
    default:
      // Print unknown % sequence to draw attention.
//	gpuputc('%');
	uartputc('%');
//	gpuputc(c);
	uartputc(c);
      break;
    }
  }
  if(locking)
    release(&cons.lock);
}
Exemplo n.º 9
0
__attribute__ ((noinline)) void uip_printip4(const uip_ipaddr_t ip4) {
	printint(uip_ipaddr1(ip4));
	printstr(".");
	printint(uip_ipaddr2(ip4));
	printstr(".");
	printint(uip_ipaddr3(ip4));
	printstr(".");
	printint(uip_ipaddr4(ip4));
}
Exemplo n.º 10
0
// Print to the console. only understands %d, %x, %p, %s.
void
cprintf(char *fmt, ...)
{
  int i, c, state, locking;
  uint *argp;
  char *s;

  locking = cons.locking;
  if(locking)
    acquire(&cons.lock);

  if (fmt == 0)
    panic("null fmt");

  argp = (uint*)(void*)(&fmt + 1);
  state = 0;
  for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
    if(c != '%'){
      consputc(c);
      continue;
    }
    c = fmt[++i] & 0xff;
    if(c == 0)
      break;
    switch(c){
    case 'd':
      printint(*argp++, 10, 1);
      break;
    case 'x':
    case 'p':
      printint(*argp++, 16, 0);
      break;
    case 's':
      if((s = (char*)*argp++) == 0)
        s = "(null)";
      for(; *s; s++)
        consputc(*s);
      break;
    case '%':
      consputc('%');
      break;
    case 'o':
      // hw1: fill in your code here. 
      // print a number in octal system
      printint(*argp++, 8, 0);
      break;
    default:
      // Print unknown % sequence to draw attention.
      consputc('%');
      consputc(c);
      break;
    }
  }

  if(locking)
    release(&cons.lock);
}
Exemplo n.º 11
0
// Print to the console. only understands %d, %x, %p, %s.
void
cprintf(char *fmt, ...)
{
    int i, c, state, locking;
    uint *argp;
    char *s;

    locking = use_console_lock;
    if(locking)
        acquire(&console_lock);

    argp = (uint*)(void*)&fmt + 1;
    state = 0;
    for(i = 0; fmt[i]; i++) {
        c = fmt[i] & 0xff;
        switch(state) {
        case 0:
            if(c == '%')
                state = '%';
            else
                cons_putc(c);
            break;

        case '%':
            switch(c) {
            case 'd':
                printint(*argp++, 10, 1);
                break;
            case 'x':
            case 'p':
                printint(*argp++, 16, 0);
                break;
            case 's':
                s = (char*)*argp++;
                if(s == 0)
                    s = "(null)";
                for(; *s; s++)
                    cons_putc(*s);
                break;
            case '%':
                cons_putc('%');
                break;
            default:
                // Print unknown % sequence to draw attention.
                cons_putc('%');
                cons_putc(c);
                break;
            }
            state = 0;
            break;
        }
    }

    if(locking)
        release(&console_lock);
}
Exemplo n.º 12
0
static int printvarg(int *varg)
{
	char scr[2];

	char *format = (char *)(*varg++);
	int pc = 0;

	for (; *format != 0; ++format) {
		if (*format == '%') {
			++format;
			if (*format == '\0')
				break;

			if (*format == '%')
				goto symbol;

			if( *format == 's' ) {
				char *s = *((char **)varg++);
				pc += printstr(s ? s : "(null)");
				continue;
			}

			if( *format == 'd' ) {
				pc += printint(*varg++, 10, 1, 'a');
				continue;
			}

			if( *format == 'x' ) {
				pc += printint(*varg++, 16, 0, 'a');
				continue;
			}

			if( *format == 'X' ) {
				pc += printint(*varg++, 16, 0, 'A');
				continue;
			}

			if( *format == 'u' ) {
				pc += printint(*varg++, 10, 0, 'a');
				continue;
			}

			if( *format == 'c' ) {
				scr[0] = *varg++;
				scr[1] = '\0';
				pc += printstr(scr);
				continue;
			}
		} else {
		symbol:
			pc += printchar(*format);
		}
	}

	return pc;
}
Exemplo n.º 13
0
Arquivo: slice.c Projeto: abustany/go
void
runtime·printslice(Slice a)
{
	runtime·prints("[");
	runtime·printint(a.len);
	runtime·prints("/");
	runtime·printint(a.cap);
	runtime·prints("]");
	runtime·printpointer(a.array);
}
Exemplo n.º 14
0
void tick_clock(struct tm *tick_time, bool stop) {
  clear();
  if((sw_butt&4)==4) { 
    reg.tm_hour = 0;
    reg.tm_min = 0;
    reg.tm_sec = 0;
    sw_butt ^= 4;//reset
  }
  if(!stop && (sw_butt&1)==1) sw_tick();
  if(++button_sec == 3) mode = delays[mode];//change mode
  switch(mode) {
  case 0: draw_dp(0b101010, 3);//time
    if (!clock_is_24h_style()) {
      if(tick_time->tm_hour > 11)
        draw(26, 0);//PM
      else
        draw(23, 0);//AM
    }
    tock(tick_time, false, clock_is_24h_style());
    break;
  case 1: draw_dp(0b100, 3);//date
    draw(days[tick_time->tm_mon * 3 + 21], 5);
    draw(days[tick_time->tm_mon * 3 + 22], 6);
    draw(days[tick_time->tm_mon * 3 + 23], 7);
    draw(tick_time->tm_mday/10, 3);
    draw(tick_time->tm_mday%10, 4);
    draw(days[tick_time->tm_wday * 3], 0);
    draw(days[tick_time->tm_wday * 3 + 1], 1);
    draw(days[tick_time->tm_wday * 3 + 2], 2);
    break;
  case 2: draw_dp(0b1010 + (((sw_butt&1)==1)?32:0) + (((sw_butt&2)==2)?0b10001:0), 3);//stopwatch
    if((sw_butt&2)==2) {
      tock(&lap, true, true);
    } else {
      tock(&reg, true, true);
    }
    break;
  case 3: printreal(value, false);
    break;
  case 4: draw_dp(1<<(direction%5), 8);//score
    printint(score, 7, false);
    break;
  case 5: draw_dp(1<<(direction%5), 8);//level
    printint(level, 7, false);
    draw(28, 0);//L
    break;
  case 6: draw_dp(1<<(direction%5), 8);//hiscore
    printint(hiscore, 7, false);
    draw(18, 0);//H
    break;
  default: break;
  }
}
Exemplo n.º 15
0
void
runtime·printslice(Slice a)
{
#line 197 "C:\Users\ADMINI~1\AppData\Local\Temp\2\makerelease686069423\go\src\pkg\runtime\slice.goc"

	runtime·prints("[");
	runtime·printint(a.len);
	runtime·prints("/");
	runtime·printint(a.cap);
	runtime·prints("]");
	runtime·printpointer(a.array);
}
Exemplo n.º 16
0
void
runtime·printslice(Slice a)
{
#line 201 "/home/pi/go_build/hg/go/src/pkg/runtime/slice.goc"

	runtime·prints("[");
	runtime·printint(a.len);
	runtime·prints("/");
	runtime·printint(a.cap);
	runtime·prints("]");
	runtime·printpointer(a.array);
}
Exemplo n.º 17
0
Arquivo: slice.c Projeto: 8l/go-learn
static void
throwslice(uint32 lb, uint32 hb, uint32 n)
{
	prints("slice[");
	runtime·printint(lb);
	prints(":");
	runtime·printint(hb);
	prints("] of [");
	runtime·printint(n);
	prints("] array\n");
	throw("array slice");
}
Exemplo n.º 18
0
void
runtime·printslice(Slice a)
{
#line 201 "/home/14/ren/source/golang/go/src/pkg/runtime/slice.goc"

	runtime·prints("[");
	runtime·printint(a.len);
	runtime·prints("/");
	runtime·printint(a.cap);
	runtime·prints("]");
	runtime·printpointer(a.array);
}
Exemplo n.º 19
0
void
runtime·printslice(Slice a)
{
#line 197 "C:\Users\gopher\AppData\Local\Temp\1\makerelease745458658\go\src\pkg\runtime\slice.goc"

	runtime·prints("[");
	runtime·printint(a.len);
	runtime·prints("/");
	runtime·printint(a.cap);
	runtime·prints("]");
	runtime·printpointer(a.array);
}
Exemplo n.º 20
0
static void printstat_1p()
{
	setattr_normal();
	if (!_WHITE_BG)
		setattr_bold();
	setcurs(1, 2);
	printlong(" %06ld ", player1.score % 1000000);
	setcurs(3, 6);
	printint(" %02d ", player1.level);
	setcurs(3, 10);
	printint(" %03d ", player1.lines);
}
Exemplo n.º 21
0
void stack2()
{
	int a;
	print("a vale: ");
	printint(a);
	print("\n");
	a=15;
	print("ahora a vale: ");
	printint(a);
	print("\n");
	fore(getppid());
	while(1);
}
Exemplo n.º 22
0
main() {
	
	//impletation1();
	
	printf("impletation2\n");
	//impletation2();
	
	int cont = strlen("hello, world");
	int cont2 = strlen("");
	printint(cont);
	printint(cont2);
	printf("%d\n", cont);
}
Exemplo n.º 23
0
// Print to the console. only understands %d, %x, %p, %s.
void
cprintf(char *fmt, ...)
{
  int i, c, locking;
  uint *argp;
  char *s;

  locking = cons.locking;	/* primero se revisa si cons.locking != 0 (2015.11.14) */
  if(locking)
    acquire(&cons.lock);

  if (fmt == 0)
    panic("null fmt");

  argp = (uint*)(void*)(&fmt + 1);
  for(i = 0; (c = fmt[i] & 0xff) != 0; i++){
    if(c != '%'){
      consputc(c);	/* aqui podemos ver que si el char no es '%' se usa static void consputc(int) */
      continue;
    }
    c = fmt[++i] & 0xff;
    if(c == 0)
      break;
    switch(c){
    case 'd':
      printint(*argp++, 10, 1);
      break;
    case 'x':
    case 'p':
      printint(*argp++, 16, 0);
      break;
    case 's':
      if((s = (char*)*argp++) == 0)
        s = "(null)";
      for(; *s; s++)
        consputc(*s);
      break;
    case '%':
      consputc('%');
      break;
    default:
      // Print unknown % sequence to draw attention.
      consputc('%');
      consputc(c);
      break;
    }
  }

  if(locking)
    release(&cons.lock);
}
Exemplo n.º 24
0
void mandSet(int width, int height)
{
	int iteMax = 200, x = 0, y;
	int b, g, i, k, r;
	double real, imag, realN, h, w;
	unsigned long hex;
	y = (abs(yMin) + yMax) / dxy;
	printint(y);

	for (h = yMin; h < yMax; h += dxy)
	{
		y--;
		x = 0;
		for (w = xMin; w < xMax; w += dxy)
		{
			x++;
			imag =  0;
			realN = real = 0;
			for (i = 0; i < iteMax; i++)
			{
				real = realN * realN - (imag * imag) + w;
				imag = 2 * realN * imag + h;
				realN = real;				

				if (real * real + imag * imag > 4)
				{
					break;
				}

			}

			if (i == iteMax)
			{
				r = 0; g = 0; b = 0;
			}
			else
			{
				k = ((i * 255) / iteMax);
				r = round(sin(0.024 * k + 0) * 127 + 128); //RED
				g = round(sin(0.024 * k + 2) * 127 + 128); //GREEN
				b = round(sin(0.024 * k + 4) * 127 + 128); //BLUE
			}

			hex = ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);

			render(x, y, hex);
		}
	}
	printint(y);
}
Exemplo n.º 25
0
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
	//mutex_lock(&plock);
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
    c = fmt[i] & 0xff;
    if(state == 0){
      if(c == '%'){
        state = '%';
      } else {
        putc(fd, c);
      }
    } else if(state == '%'){
      if(c == 'd'){
        printint(fd, *ap, 10, 1);
        ap++;
      } else if(c == 'x' || c == 'p'){
        printint(fd, *ap, 16, 0);
        ap++;
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
        putc(fd, *ap);
        ap++;
      } else if(c == '%'){
        putc(fd, c);
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
        putc(fd, c);
      }
      state = 0;
    }
  }
  //mutex_unlock(&plock);
}
Exemplo n.º 26
0
void main()
{
  int x;
  int a, b, c;

  a = 2;
  b = 3;
  c = 4;


  if (a!=2) {
    printint(a);    // Not true!
  } else {
    printint(666);  // expecting 666
  };
}
Exemplo n.º 27
0
static void printreal(double x, bool ex) {
  bool neg = false;
  if(x < zero) {
    neg = true;
    x = -x;
  }
  if(x == zero|| (!neg && x < 0.0001e-99) || (neg && x < 0.001e-99)) {
    draw_dp(0b10000, 8);
    draw(0, 7);
    return;//Zero rounding
  }
  if((!neg && x > 9.9999e+99) || (neg && x > 9.999e+99) || x != x) {//NaN test too 
    error = true;
    draw(15, 7);
    return;//Overflow
  }
  double mask = ((ex)?100000.0:100000000.0);//use exponent
  mask = ((!neg)?mask:(mask * tenth));//leave space for negative sign
  if(x >= mask || x <= one/mask) {//sci notation as too big
    sci(neg, x);
    return;
  }
  dp = (ex?5:8);//set zero placed deciaml
  //either defered as sci exponent, zero or error printed so far!!
  bool zeros = (x < one);
  int check = 0;
  while((zeros)?(dp > (neg?2:1)):(x < mask)) {
    check = (int)x;
    if((double)check == x) break;//exact
    --dp;
    x *= 10;
  }
  draw_dp(0b10000, dp);
  printint(neg?-check:check, ex?4:7, zeros);//integer part drawn
}
Exemplo n.º 28
0
static void PrintVector (rcintvec_t v)
{
    cout << "{ ";
    foreach (intiter_t, i, v)
	printint (*i);
    cout << "}\n";
}
Exemplo n.º 29
0
void 
finalcleanup ( void ) 
{
  /* 10 */ smallnumber c  ;
  c = curmod ;
  if ( jobname == 0 ) 
  openlogfile () ;
  while ( inputptr > 0 ) if ( ( curinput .indexfield > 15 ) ) 
  endtokenlist () ;
  else endfilereading () ;
  while ( loopptr != 0 ) stopiteration () ;
  while ( openparens > 0 ) {
      
    print ( 1078 ) ;
    decr ( openparens ) ;
  } 
  while ( condptr != 0 ) {
      
    printnl ( 1079 ) ;
    printcmdmod ( 2 , curif ) ;
    if ( ifline != 0 ) 
    {
      print ( 1080 ) ;
      printint ( ifline ) ;
    } 
    print ( 1081 ) ;
    ifline = mem [condptr + 1 ].cint ;
    curif = mem [condptr ].hhfield .b1 ;
    loopptr = condptr ;
    condptr = mem [condptr ].hhfield .v.RH ;
    freenode ( loopptr , 2 ) ;
  } 
  if ( history != 0 ) {
      
    if ( ( ( history == 1 ) || ( interaction < 3 ) ) ) {
	
      if ( selector == 3 ) 
      {
	selector = 1 ;
	printnl ( 1082 ) ;
	selector = 3 ;
      } 
    } 
  } 
  if ( c == 1 ) 
  {
	;
#ifdef INIMF
    if ( iniversion ) 
    {
      storebasefile () ;
      goto lab10 ;
    } 
#endif /* INIMF */
    printnl ( 1083 ) ;
    goto lab10 ;
  } 
  lab10: ;
} 
Exemplo n.º 30
0
int uvl_entry()
{
	print("\fHello World!", 0x00000000, 0x00555555);
	print("\vHello World!", 0x00000000, COLOR_TRANS);
	print("\nHello World2", 0x000000FF, COLOR_TRANS);
	print("\nHello World3", 0x000000FF, COLOR_TRANS);
	printint(0xDEADBEEF, 0x0000FFFF, COLOR_TRANS);
}