Embedded Systems
Homework #1
(Due: Oct. 8, 2003, in class)

  1. Run the following program on a computer of your choice and tell whether its execution can be completed in 100 msec, assuming no interrupt.

    #define TRUE 1
    #define FALSE 0
    #define SIZE 266144

    char flags[SIZE+1];

    main()
    {
    register int i, prime, k, count, iter;

    count = 0;
    for (i = 0; i <= SIZE; ++i)
    ¡@¡@¡@flags[i] = TRUE;
    for (i = 0; i <= SIZE; ++i)
    {
    ¡@¡@¡@if (flags[i])
    ¡@¡@¡@{
    ¡@¡@¡@ ¡@¡@¡@prime = i + i + 3;
    ¡@¡@¡@¡@¡@¡@for (k = i + prime; k <= SIZE; k+= prime)
    ¡@¡@¡@¡@¡@¡@¡@¡@¡@flags[k] = FALSE;
    ¡@¡@¡@¡@¡@¡@++count;
    ¡@¡@¡@}
    }
    exit(0);
    }

  2. List three possible methods to improve the above code by 20%.
  3. Do exercise Q2-10(a) in the textbook.
  4. Do exercise Q2-22 in the textbook.