Altera Nios II C2H Compiler User Manual

Page 50

Advertising
background image

3–10

9.1

Altera Corporation

Nios II C2H Compiler User Guide

November 2009

One-to-One C-to-Hardware Mapping

Table 3–4

shows an example of a

switch

statement converted to

equivalent

if-else

statements.

Figure 3–7

shows the logic that results of translating the

if-else

code

from

Table 3–4

.

Table 3–4. switch Statement Converted to if-else Statements

switch Implementation

if-else Implementation

switch (byte_select)

{

case 1:

out = in & 0x0000ff00;

break;

case 2:

out = in & 0x00ff0000;

break;

case 3:

out = in & 0xff000000;

break;

default:

out = in & 0x000000ff;

}

if (byte_select == 1)

out = in & 0x0000ff00;

else

if (byte_select == 2)

out = in & 0x00ff0000;

else

if (byte_select == 3)

out = in & 0xff000000;

else

out = in & 0x000000ff;

Advertising