CO Lab Manual
Course Page
  • Course Information
    • Welcome
    • Introduction
    • Your Contributions
    • Lab Sessions and Etiquette
    • Team Setup
    • Assumed Prior Knowledge
  • Setup Guides
    • GitHub Repository Setup
    • Technical Setup
      • Windows
      • Linux
      • macOS
    • GitHub SSH Setup
    • Framework Setup
  • Reference Documentation
    • Introduction to the Documentation
    • A Brief History Lesson
    • Syntax (Intel vs. AT&T)
      • Section Exercises
    • Memory
      • Memory Management
      • Section Exercises
    • Registers
      • Section Exercises
    • Instructions
    • Subroutines
      • Calling Subroutines
      • Writing Subroutines
      • Section Exercises
    • Input/Output
      • Printing to the Terminal
      • Reading from the Terminal
      • Section Exercises
    • Programming Constructs
    • Assembler Directives
    • C/C++ vs Assembly
    • Building and Running Programs
    • Address Sanitization
    • A0: A Running Example
  • Assignments
    • Introduction to the Assignments
    • Mandatory Assignments
      • A1: Subroutines and I/O
      • A2: Recursion
    • Extra Assignments
      • A3-a: Fibonacci Calculator
      • A3-b: Fibonacci REPL
      • A4: Diff
      • A5: Printf
      • A6: HPC
      • A7: Bitmap
      • A8: Game
  • Appendix
    • Acknowledgments
    • Rules and Regulations
    • Frequently Asked Questions
    • How to use a Debugger
Powered by GitBook
On this page
  1. Reference Documentation

C/C++ vs Assembly

PreviousAssembler DirectivesNextBuilding and Running Programs

Last updated 4 months ago

By reaching this section of the manual, you should have gained a strong theoretical base regarding Assembly particularities. However, when writing your first Assembly code, a lot of "Why?" and "How?" questions will be raised.

Understanding the relation between Assembly and a higher programming language can represent the first step in writing your first program in Assembly. In order to emphasize the relation between different Assembly chunks of code and higher language elements, we provide the following example showcasing the same program written in C++, C and Assembly.

No matter the way you look at this example (either from C to Assembly or from Assembly to C) there are aspects you should pay attention to before addressing more complex examples.

  • follow the flow of the program and understand the placement of the prologue and epilogue;

  • understand stack alignment;

  • find for each C line of code the corresponding Assembly block and think about how that block can be written differently (if possible) in order to have the same outcome.

Once you mark those checkpoints on this example, you are ready for more complex Assembly code.

C++ -> C -> Assembly