🔬 Lab
CS 240 Lab 9
Learning Goals & Reflection
CS 240 Lab 9
Learning Goals
Core Goals
Students can:
- Write assembly code for simple programs.
- Use segment markers to organize code and data values appropriately.
- Declare global variables and other statically allocated data, including numbers, arrays of numbers, and strings, using appropriate symbols and directives.
- Declare functions using symbols and assembly code.
- Call your own functions from within other functions using jump instructions along with appropriate argument setup and return value processing.
- Call
printf
andscanf
for basic I/O using appropriate arguments via registers and maintaining the required stack pointer alignment. - Write assembly code for an entire program from scratch, and compile
it into a binary using
gcc
.
- Explain how array data is stored in memory and accessed using
assembly code.
- Determine the size in bytes for an array declared in C code or using assembly directives, by reading the code.
- Convert between equivalent array declarations using the
.int
vs..byte
directives. - Write out the memory access expressions necessary to load specific
values from an array using the
mov
instruction. - Identify appropriate partial destination register names that will
cause
mov
to load 1, 4, or 8 bytes from memory into (parts of)%rax
. - 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.
- Explain how multiple values from 1-byte or 2-byte arrays will appear when accessed as 4-byte integers.
- Explain how 2D arrays are stored by C and accessed using assembly
code.
- 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.
- Write the assembly code necessary for accessing a 2D array using row and column indices.
- 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.
- 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
- Write assembly code for simple programs.
- Implement caller- and callee-save logic correctly within hand-written assembly functions.
- Diagnose program crashes due to stack misalignment and/or unintended memory access for small constants.
- Explain how array data is stored in memory and accessed using
assembly code.
- 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. - 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.
- Explain how string data will appear if loaded as an integer, and vice versa.
- Identify appropriate partial destination register names that will
cause
Extra goals
- Write assembly code for simple programs.
- Use symbols and conditional jump instructions within function code to implement conditionals and/or loops.
Reflection
Note: Make sure to use the ‘print’ dialog to save this page as a PDF when you’re done.
I’m most confident in (list a few):
I’m least confident in (list a few):
Questions (please take the time to ask at least one, thinking of a question will help you cement what you’ve learned):