w6-part3-four

w6-part3-four - For loop Machine-Level Programming III:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 1 Machine-Level Programming III: Control Flow, Stack frame z Topics z Control Flow z For loop z Stack frames 2 For loop z Test z If test is true execute z For loop body z Update loop variable z Else exit for ( Init ; Test ; Update ) Body for ( I=0 ; I < 211 ; i++ ){ Body} mov $0 , %esi startfor: cmp $211, %esi jge exitfor body inc %esi jmp startfor Exitfor: 3 For loop: another implementation z Jmp to Test z For loop z body z Update loop variable z Test: if true jmp to body for ( Init ; Test ; Update ) Body for ( I=0 ; I < 211 ; i++ ){ Body} mov $0 , %esi jmp fortest startfor: body inc %esi fortest: cmp $211, %esi jl startfor “For” “While” “For” “While” for ( Init ; Test ; Update ) Body Init ; while ( Test ) { Body Update ; } Goto Version Init ; if (! Test ) goto done ; loop: Body Update ; if ( Test ) goto loop ; done: While Version For Version Do-While Version Init ; if (! Test ) goto done ; do { Body Update ; } while ( Test ) done :
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 5 “For” Loop Compilation “For” Loop Compilation Init result = 1 Test p != 0 Update p = p >> 1 Body { if (p & 0x1) result *= x; x = x*x; } Goto Version Init ; if (! Test ) goto done ; loop : Body Update ; if ( Test ) goto loop ; done : result = 1; if (p == 0) goto done ; loop : if (p & 0x1) result *= x; x = x*x; p = p >> 1; if (p != 0) goto loop ; done : 6 Programs & Memory z The Von Neumann: z programs & data are stored in memory z Recall assembly code converted to object code ( Assembler ) z Labels are nothing more then address locations of instructions z Here: Move %eax, %edx z z Jmp Here instructions global data run-time
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

w6-part3-four - For loop Machine-Level Programming III:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online