GOALS

  • Get familiar with more x86_64 assembly language
  • Practice learning how C code constructs get translated into equivalent assembly language

Logistics

This is a paired assignment, so you should continue to work with your assigned partner, if you have one. If you chose not to be assigned a partner, you must work individually (you can’t pick your own partner!). As usual, you can get help as detailed in the collaboration document. You should submit only one assignment to Gradescope for your pair and add your partner to the submission. If for some reason you and your partner can’t make things work, you can split, but you have to let me know asap.

This assignment (i.e. part 2) is due Wednesday May 1st at 10pm. As with all assignments, you will have the opportunity to individually revise this submission based on feedback.

Assessment

To demonstrate proficiency, your submission needs to:

  • Pass the autograder tests (which are checking that your C produces the correct output)
  • Have accurate descriptions for each puzzle

To demonstrate mastery, your submission needs to:

  • Nearly perfectly recreate the provided assembly
  • Have clear and concise descriptions for each puzzle

Background

More puzzles! Everything is the same as the previous homework, but with some of the more complicated functionality that you’ve been learning about. You should continue to use the Compiler Explorer. You’ll put some C code into the input panel, and the output panel will show you the assembly language generated by the selected compiler. As you adjust your C code, you’ll be able to watch the changes in the assembly language, and then compare your assembly code to the puzzle’s code.

WHAT YOU SHOULD DO?

In the asm-to-c2-package.tar package, you will find several files named puzzle4.asm, puzzle5.asm, and puzzle6.asm. For each puzzle, your job will go like this:

  • Study the puzzleN.asm code to understand what it does. You should try to understand it holistically rather than just line-by-line, so you’ll be able to describe the code’s purpose in a single short sentence.
  • Write an equivalent C function (or sometimes two functions). Then use the Compiler Explorer to compile it to assembly, and see how closely your assembly matches the contents of puzzleN.asm. Refine your code until you feel the match-up is close enough. Exact matches are great, of course, but close matches might also be correct. Very slight changes in source code can make changes in the assembly code, even if the code’s end result is unchanged. (Note that your function names should match the very poorly chosen names in the assembly for the sake of the autograder.)
  • Write a one-sentence description of the purpose of the code for the current puzzle (e.g., you can imagine a description like “this function takes one positive integer parameter n and returns the nth prime number”).
  • Put your code in a file named puzzleN.c, and put your name(s) and one-sentence description in the file header at the top of puzzleN.c.

Hand it all into to Gradescope by uploading each of your .c files. Gradescope will run the files to see if they output the same values at the assembly and the human grader will check for how close your C code matches the original source and the quality of your descriptions.

COMPILER EXPLORER SETTINGS

Set it up like this:

Screnshot of Compiler Explorer

HAVE FUN!