Final, CMAC 3100, Fall 2024

Name ______________________________________


  1. Calling Convention.
    1. [4 points] What is a calling convention and why should it be followed?
    2. [4 points] Give two different rules that are part of a calling convention.
    3. [2 points] When is it save not to follow the calling convention?
    4. [5 points] Write the beginning and ending code for a non-leaf function in NASM assembly that will use R14 and R15 (preserved registers).

  2. Activation Records or Stack Frames.
    1. [2 points] What is an activation record?
    2. [4 points] Why is an activation record needed?
    3. [4 points] What items might be stored in an activation record?

  3. Segments
    1. [6 points] Name, describe, and list the items that are contained in the three NASM program segments used in this class.

  4. Write each of the following code segments in NASM assembly. You must follow the calling convention (or note where you should do something but don't remember how).
    1. [5 points] Write a function that takes the base address of a null terminated string and converts all upper case letters to lower case. ('A' = 65, 'a' = 97).
    2. [5 points] Write a function that takes the base address of a null terminated string and returns the length of that string in rax.
    3. [5 points] Write a function that uses the previous functions to print a message in all lower case. You should call a PrintString function. The PrintString function expects the base address of the string in rdi and the length of the string in rsi.
    4. [4 point] Write a main program that declares a string and calls the above function.