telecom • networking • design

an EventHelix.com blog


Leave a comment

Map C switch and if statements to assembly code

This article covers the code generation for if-else and switch statements.

Switch jump table

The code generated for a switch statement varies a lot from one compiler to another. In fact, a given compiler might generate different code in different scenarios. The choice of the code to be generated depends upon the number and range spread of individual case statements.

Different cases of generation of a switch statement are:

Advertisements


Leave a comment

Translate C for loop, while loop, struct access and array index into assembly

We have covered the C calling convention,  frame pointers and the assembly code in the previous article. This article will focus on the code generation for:

 

      C to assembly for loops, structure access and array indexing


Leave a comment

C Function Call to Assembly Translation – Frame Pointer Operations

Even though most programming is now carried out in high level languages, a good understanding of the generated assembly code really helps in debugging, performance analysis and performance tuning.

In this article, we will discuss the assembly code generated for function calling, parameter passing and local variable management. Frame pointer operations in a function call are described in detail.

C function call mapped to assembly - learn about frame pointer operations

We follow the lifecycle of a function call:

  1. Pushing parameters
  2. Invoking function
  3. Setting up the frame pointer
  4. Dismantling the frame and restoring the callers frame at function exit
  5. The caller popping the parameters.

C to Assembly : function calls and frame pointer operations