# X goto done loop result x 0x1 x 1 if x goto loop done

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: val = x > 0 ? x*=7 : x+=3; ¢༊  Ambos valores consiguen ser calculados ¢༊  Debe estar libre de efectos secundarios 31 EJEMPLO DEL “DO-WHILE” C Code int pcount_do(unsigned x) { int result = 0; do { result += x & 0x1; x >>= 1; } while (x); return result; } Goto Version int pcount_do(unsigned x) { int result = 0; loop: result += x & 0x1; x >>= 1; if (x) goto loop; return result; } ¢༊  Contar el número de 1 en el argumento x (“popcount”) ¢༊  Usar salto condicional entre continuar un bucle o para salir del bucle 32 COMPILACIÓN DEL “DO-WHILE” Goto Version int pcount_do(unsigned x) { int result = 0; loop: result += x & 0x1; x >>= 1; if (x) goto loop; return result; } Registers: %edx x %ecx result ¢༊  movl .L2: movl andl addl shrl jne loop \$0, %ecx %edx, %eax \$1, %eax %eax, %ecx %edx .L2 # result = 0 # loop: # # # # t=x&1 result += t x >>= 1 If !0, goto 33 TRADUCCIÓN GENERAL DEL C Code do Body while (Test); ¢༊  “DO-WHILE” Goto Version loop: Body if (Test) goto loop Body: { Statement1; Statement2; … Statementn; } ¢༊  Test returns integer ༉  = 0 interpretado false ≠ 0 interpretado true ༉  34 EJEPMLO DEL “WHILE” C Code int pcount_while(unsigned x) { int result = 0; while (x) { result += x & 0x1; x >>= 1; } return result; } ¢༊  Es ༉  Goto Version int pcount_do(unsigned x) { int result = 0; if (!x) goto done; loop: result += x & 0x1; x >>= 1; if (x) goto loop; done: return result; } el código equivalente a la...
View Full Document

## This document was uploaded on 04/05/2014.

Ask a homework question - tutors are online