int main(void)
{
	print_S();
	print_C();

	return 0;
}
Esempio n. 2
0
int main()
{
  /* Initialization of arrays */
  const int x5[10] = { 1, 2, 3 };
  char x17[] = "Hello!";
  char * x18 = "Hello!";
  char * x19[2] = { "Hello", "world!" };
  char x20[3] = "Hello!";
  char x21[10] = "Hello!";
  printf("x5 = { ");
  for (int i = 0; i < 10; i++) printf("%d, ", x5[i]);
  printf("}\n");
  printf("x17[%d] = { ", (int) sizeof(x17));
  print_chars(x17, sizeof(x17));
  printf("}\n");
  printf("x18 = \"%s\"\n", x18);
  printf("x19 = { \"%s\", \"%s\" }\n", x19[0], x19[1]);
  printf("x20 = { ");
  print_chars(x20, sizeof(x20));
  printf("}\n");
  printf("x21 = { ");
  print_chars(x21, sizeof(x21));
  printf("}\n");
  /* Local const arrays */
  printf("f(0,42) = %d, f(1,42) = %d, f(2,42) = %d, f(3,42) = %d, f(4,42) = %d\n",
         f(0,42), f(1, 42), f(2, 42), f(3, 42), f(4, 42));
  /* Structs/unions */
  struct P p1 = { 66, 77 };
  struct S s1 = { 0, p1 };
  print_S("s1", &s1);
  struct S s2 = { .a.y = 1, .u.c[4] = 'x', .u.b = p1 };
  print_S("s2", &s2);
  /* ISO C99 and recent Clang say s3.a.y = 77
     GCC and earlier CompCert versions say s3.a.y = 0
     Now CompCert fails on an error "unsupported reinitialization". */
#if 0
  struct S s3 = { .tag = 1, .a = p1, .a.x = 1, .u.c = "Hello!", .u.c[7] = 'X' };
  print_S("s3", &s3);
#endif
  /* This other reinitialization is correctly supported, though. */
  struct S s4 = { .tag = 0, .a.x = 1, .a = p1, .u.b = 88, 99 };
  print_S("s4", &s4);
  return 0;
}
Esempio n. 3
0
int main(void) {
  CPU_PRESCALE(0);
  MCUCR |= 0x80; MCUCR |= 0x80;
  usb_init();
  while(!usb_configured());
  keyboard_init();

  for(uint8_t t=0; t<6; t++) {
    for(uint8_t r = 0; r < NUMBER_OF_ROWS; r++) {
      pull_row(r);
      _delay_us(16);
      sprintf(tmp_str, "row %02d: ", r);
      print_S(tmp_str);
      _delay_ms(5);
      for(uint8_t c = 0; c < NUMBER_OF_COLUMNS; c++) {
        bool b = probe_column(c);
        if(!b) {
          print_S("0");
        }
        else
          print_S("1");
      }
      release_rows();
      print_S(" ");
      for(uint8_t c = 0; c < NUMBER_OF_COLUMNS; c++) {
        bool b = probe_column(c);
        if(b) {
          print_S("1");
        }
        else
          print_S("0");
      }
      print_S("\n");
      leds = mask-leds;
      update_leds(leds);
      _delay_ms(200);
    }
  }
  
  EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
  TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
  DDRB = 0; DDRC = 0; DDRD = 0;
  PORTB = 0; PORTC = 0; PORTD = 0;
  asm volatile("jmp 0x7000");

}
Esempio n. 4
0
static inline
void print_int(uint16_t data, uint8_t base)
{
    char buf[7] = {'\0'};
    char *p = &buf[6];
    if ((base & SIGNED) && (data & 0x8000)) {
        data = -data;
        buf[0] = '-';
    }
    base &= ~SIGNED;
    uint16_t n;
    do {
        n = data;
        data /= base;
        *(--p) = itoc(n - data*base);
    } while (data);
    if (buf[0]) *(--p) = buf[0];
    print_S(p);
}
Esempio n. 5
0
Elem & Machine::execute(std::ostream &out)
{
    Instruction *command;
    std::shared_ptr<Elem> command_ptr;

    Elem *ADD(new Instruction("ADD"));
    Elem *MUL(new Instruction("MUL"));
    Elem *SUB(new Instruction("SUB"));
    Elem *DIV(new Instruction("DIV"));
    Elem *REM(new Instruction("REM"));
    Elem *EQ(new Instruction("EQ"));
    Elem *LEQ(new Instruction("LEQ"));
    Elem *SEL(new Instruction("SEL"));
    Elem *LD(new Instruction("LD"));
    Elem *LDC(new Instruction("LDC"));
    Elem *LDF(new Instruction("LDF"));
    Elem *CAR(new Instruction("CAR"));
    Elem *CDR(new Instruction("CDR"));
    Elem *CONS(new Instruction("CONS"));
    Elem *NIL(new Instruction("NIL"));
    Elem *DUM(new Instruction("DUM"));
    Elem *AP(new Instruction("AP"));
    Elem *RAP(new Instruction("RAP"));
    Elem *RTN(new Instruction("RTN"));
    Elem *JOIN(new Instruction("JOIN"));
    Elem *STOP(new Instruction("STOP"));

    while (!C->empty())
    {
        if (out != 0x0)
        {
            print_S(out);
            print_E(out);
            print_C(out);
            out << std::endl;
        }

        command_ptr = C->pop_ret();
        command = dynamic_cast<Instruction*>(&*command_ptr);
        if (command == nullptr) throw Exception("Execute", "FatalError");

        if (*command == *ADD)       this->ADD();
        else if (*command == *MUL)  this->MUL();
        else if (*command == *SUB)  this->SUB();
        else if (*command == *DIV)  this->DIV();
        else if (*command == *REM)  this->REM();
        else if (*command == *EQ)   this->EQ();
        else if (*command == *LEQ)  this->LEQ();
        else if (*command == *SEL)  this->SEL();
        else if (*command == *LD)   this->LD();
        else if (*command == *LDC)  this->LDC();
        else if (*command == *LDF)  this->LDF();
        else if (*command == *CAR)  this->CAR();
        else if (*command == *CDR)  this->CDR();
        else if (*command == *CONS) this->CONS();
        else if (*command == *NIL)  this->NIL();
        else if (*command == *DUM)  this->DUM();
        else if (*command == *AP)   this->AP();
        else if (*command == *RAP)  this->RAP();
        else if (*command == *RTN)  this->RTN();
        else if (*command == *JOIN)  this->JOIN();
        else if (*command == *STOP) { return (*(this->STOP()));}
        else throw Exception("Execute", "Expected 'instruction' but greeted constant.");
    }

    throw Exception("Execute", "FatalError");
}