Map C switch and if statements to assembly code

EventHelix
Software Design
Published in
Jun 2, 2017

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

Code generation for a switch statement (case values are in a narrow range)

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:

--

--