C next line is not legal c code jt7 loca locdef

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: est-expr; if (t) goto true; else-statement goto done; true: then-statement done: 118 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS code/asm/abs.c 1 2 3 4 5 6 7 code/asm/abs.c 1 2 3 4 5 6 7 8 9 10 11 12 13 int absdiff(int x, int y) { if (x < y) return y - x; else return x - y; } code/asm/abs.c int gotodiff(int x, int y) { int rval; if (x < y) goto less; rval = x - y; goto done; less: rval = y - x; done: return rval; } code/asm/abs.c (a) Original C code. (b) Equivalent goto version of (a). 1 2 3 4 5 6 7 8 9 10 movl 8(%ebp),%edx movl 12(%ebp),%eax cmpl %eax,%edx jl .L3 subl %eax,%edx movl %edx,%eax jmp .L5 .L3: subl %edx,%eax .L5: Get x Get y Compare x:y If <, goto less: Compute y-x Set as return value Goto done: less: Compute x-y as return value done: Begin completion code (c) Generated assembly code. Figure 3.11: Compilation of Conditional Statements C procedure absdiff (a) contains an if-else statement. The generated assembly code is shown (c), along with a C procedure gotodiff (b) that mimics the c...
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