Final, CMAC 3100, Fall 2024
Name ______________________________________
- Please write your name at the top of this page.
- Please staple this page on top of your answers.
- The weight for each question is given.
- Use as much paper as you wish, but make your answers are legible.
- Please label your answers with the question number.
- For computations, please draw a rectangle around your final answer.
- Please answer each question thoughtfully and carefully.
- You may use a calculator, but not your phone or any network device.
- Calling Convention.
- [4 points] What is a calling convention and why should it be followed?
- [4 points] Give two different rules that are part of a calling convention.
- [2 points] When is it save not to follow the calling convention?
- [5 points] Write the beginning and ending code for a non-leaf function in NASM assembly that will use R14 and R15 (preserved registers).
- Activation Records or Stack Frames.
- [2 points] What is an activation record?
- [4 points] Why is an activation record needed?
- [4 points] What items might be stored in an activation record?
- Segments
- [6 points] Name, describe, and list the items that are contained in the three NASM program segments used in this class.
- 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).
- [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).
- [5 points] Write a function that takes the base address of a null terminated string and returns the length of that string in rax.
- [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 point] Write a main program that declares a string and calls the above function.