CMPS-2240 Assembly Language

Summer Programming Exercise


Write a program named 2240/summer/summer1.c

Programming tasks:

   1. Generate a random number using the C library function rand().
      Do not seed the random number generator with srand().

   2. Store the number in an unsigned 32-bit integer variable.

   3. Look at just the 15 least-significant bits of the number.

   4. Take that value and store it in an unsigned 16-bit variable.

   5. Compare the value to 2,240.

      If equal...
          display a message.
          indicate how many tries it took.
          end the program.
      Otherwise...
          go back to step 1, using a goto statement.


Programming rules
-----------------
This is not a C++ program.
Do not include any C++ header files.
You may include <stdlib.h> and <stdio.h>


Programming tips
----------------
Compile your program like this: gcc summer1.c -Wall

I recommend that your program uses a mask with the & operator
to transfer the value from the 32-bit variable to the 16-bit variable.

    example:

       0110100111010001010110001100101000    <---- random value
     & 0000000000000000000111111111111111    <---- mask
       ----------------------------------
       0000000000000000000010001100101000    <---- result


I also recommend that your program output is very clean and tells the
user something about what the program is doing and what they are seeing.

I recommend you print output using the printf function.
If you have never used it, go read about it.

This whole program is just a few lines of code. Get to work on it.

I will grade your program and give it a score.
You will be able to correct your errors and improve your score, during summer.