G l4 label l10 marks the start of this allocation the

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: ne 8). Creating a table of register usage, such as we have shown in Figure 3.12(b) is a very helpful step in analyzing an assembly language program, especially when loops are present. Practice Problem 3.10: For the following C code: 1 2 3 4 5 6 int dw_loop(int x, int y, int n) { do { x += n; y *= n; n--; 3.6. CONTROL 121 code/asm/fib.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 int fib_dw(int n) { int i = 0; int val = 0; int nval = 1; do { int t = val + nval; val = nval; nval = t; i++; } while (i < n); return val; } code/asm/fib.c (a) C code. 1 2 3 4 5 6 7 8 Register Usage Register Variable Initially %ecx i 0 %esi n n %ebx val 0 %edx nval 1 %eax t – .L6: leal (%edx,%ebx),%eax movl %edx,%ebx movl %eax,%edx incl %ecx cmpl %esi,%ecx jl .L6 movl %ebx,%eax loop: Compute t = val + nval copy nval to val Copy t to nval Increment i Compare i:n If less, goto loop Set val as return value (b) Corresponding assembly language code. Figure 3.12: C and Assembly Code for Do-While Version of Fibonacci Program. Only the code inside the loop is shown. 122 7 8 9 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS...
View Full Document

Ask a homework question - tutors are online