Flow Control

Conditional Branches

Problem: Write a program that will find the sum of the first 10 odd numbers


sum = 0;
for(i=0;i<10;i+=2) {
  sum += i; 
}


        ADD R4, R0, R0         ; R4 is the sum
        ADD R3, #19, R0        ; stick 19 in Register 0
        ADD R2,#1, R0          ; R2 is the lcv
top:    SUB R0, R2, R0         ; if i > 19
        BRGT out               ; quit
	NOP                    ; fill the bds
	ADD R4, R4, R2         ;  sum += i;
	ADD R2, #2, R2         ;  i+= 2;
        BRANCH top
	nop                    
out:    
How can we rearrange this to eliminate nop BDS after the BRANCH?