CS 240 Lab 9

Learning Goals & Reflection

CS 240 Lab 9

Learning Goals

Core Goals

Students can:

  1. Write assembly code for simple programs.
    1. Use segment markers to organize code and data values appropriately.
    2. Declare global variables and other statically allocated data, including numbers, arrays of numbers, and strings, using appropriate symbols and directives.
    3. Declare functions using symbols and assembly code.
    4. Call your own functions from within other functions using jump instructions along with appropriate argument setup and return value processing.
    5. Call printf and scanf for basic I/O using appropriate arguments via registers and maintaining the required stack pointer alignment.
    6. Write assembly code for an entire program from scratch, and compile it into a binary using gcc.
  2. Explain how array data is stored in memory and accessed using assembly code.
    1. Determine the size in bytes for an array declared in C code or using assembly directives, by reading the code.
    2. Convert between equivalent array declarations using the .int vs. .byte directives.
    3. Write out the memory access expressions necessary to load specific values from an array using the mov instruction.
    4. Identify appropriate partial destination register names that will cause mov to load 1, 4, or 8 bytes from memory into (parts of) %rax.
    5. Predict what values will be read when reading memory beyond the end of a global array variable but still within memory allocated to other global variables.
    6. Explain how multiple values from 1-byte or 2-byte arrays will appear when accessed as 4-byte integers.
  3. Explain how 2D arrays are stored by C and accessed using assembly code.
    1. Determine the size in bytes for a 2D array declared in C code, and contrast this with the size necessary to store a true array-of-arrays.
    2. Write the assembly code necessary for accessing a 2D array using row and column indices.
    3. Explain what will happen when accessing a 2D array using out-of-bounds row and/or column indices, including which reads will have predictable results based on the array contents alone.
    4. Determine the 1D array which is equivalent to a given 2D array in terms of the bytes stored in memory, as well as the 2D array which is equivalent to a given 1D array for a specific row length.

Stretch goals

  1. Write assembly code for simple programs.
    1. Implement caller- and callee-save logic correctly within hand-written assembly functions.
    2. Diagnose program crashes due to stack misalignment and/or unintended memory access for small constants.
  2. Explain how array data is stored in memory and accessed using assembly code.
    1. Identify appropriate partial destination register names that will cause mov to load 1, 2, 4, or 8 bytes from memory into (parts of) various destination registers.
    2. Explain how 1-, 2-, 4-, and 8-byte values will appear when either read as part of a larger value, or when read in part as a smaller value.
    3. Explain how string data will appear if loaded as an integer, and vice versa.

Extra goals

  1. Write assembly code for simple programs.
    1. Use symbols and conditional jump instructions within function code to implement conditionals and/or loops.

Reflection

Fill out the CS 240 Lab 9 Reflection form to complete today’s lab reflection.