Machine level representation of c programs suppose

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: as can be seen in the goto code (b). First, rather than using variable i as a loop variable and comparing it to n on each iteration, the compiler has introduced a new loop variable that we call “nmi”, since relative to the original code, its value equals Ò . This allows the compiler to use only three registers for loop variables, compared to four otherwise. Second, it has optimized the initial test condition (i < n) into (val < n), since the initial values of both i and val are 1. By this means, the compiler has totally eliminated variable i. Often the compiler can make use of the initial values of the variables to optimize the initial test. This can make deciphering the assembly code tricky. Third, for 124 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS code/asm/fib.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 code/asm/fib.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 int fib_w(int n) { int i = 1; int val = 1; int nval = 1; while (i < n) { int t = val+nval; val = nval; nval = t; i++; } retur...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online