csci 10 :: book learning challenge 12 (due mon, nov 14)
Submitting your work:

Complete this exercise on your own.

Fill in all of the "Answer" boxes, then print the answer grid that you see after you press "Prepare for printing".

Staple all pages together and submit to the instructor on the date listed above.

Questions:

Read AoA V2 2.8, V3 1.7 and answer the following:

Your name:
  1. Write the code to (1) dynamically allocate 20 bytes in memory (using mem.alloc), (2) store the address returned in the variable memAddress that is declared below, and (3) free the memory using memAddress.
    static memAddress: dword;
    Answer:
  2. Write the code to (1) dynamically allocate 20 bytes in memory (using mem.zalloc), (2) store the address returned in the variable memAddress that is declared below, and (3) free the memory using memAddress.
    Answer:
  3. Read the documentation for mem.alloc and mem.zalloc in the standard library documentation for HLA here. What is the most significant difference between mem.alloc and mem.zalloc?
    Answer:
  4. Can mem.alloc and mem.zalloc raise exceptions? If so, (1) what would cause one of these routines to raise an exception, and (2) what exception(s) are raised?
    Answer:
  5. Write the instruction to dynamically allocate memory for a single int32 variable, using @size to compute the number of bytes required. What register will contain the address of the dynamically allocated int32 variable?
    Answer:
  6. Write the mov instruction required to store the value -999 into the memory location allocated by the instruction you wrote in question #5 above. What addressing mode did you use?
    Answer:
  7. Write the instruction to free the memory you allocated in question #5 above.
    Answer:
  8. Write the code to (1) dynamically allocate an array of 10 uns16, using @size, then (2) write the code to free this memory.
    Answer:
  9. Briefly explain what it means that mem.alloc dynamically allocates memory in contiguous locations. Why is this important for programmers who are dynamically allocating arrays?
    Answer:
  10. What is another term, besides address, used in your book to describe the memory address returned by a call to mem.alloc?
    Answer:
  11. Briefly explain (1) what the variable int16Ptr below can be used to store, and (2) how many bits of data can be stored in int16Ptr.
    static int16Ptr: pointer to int16;
    Answer:
  12. Write the code to declare a pointer to an uns8, using the pointer to syntax of HLA. Name your pointer uns8Ptr.
    Answer:
  13. Write the code to declare a pointer to an uns8, using a dword. Name your pointer uns8Ptr.
    Answer:
  14. Write the code to (1) declare a pointer named int32Array (using pointer to syntax) to an int32, (2) dynamically allocate enough bytes to accommodate an array of 20 int32, (3) store the address/pointer returned by the allocation to int32Array, and (4) free the memory using int32Array.
    Answer:
  15. List the five common pointer problems mentioned in your text.
    Answer:

Total points for this book learning challenge:

150 points