1 Jun 2013

Implementing for loop on DLX Program

Implementing for loop on DLX Program is similar like DLX program while loop except variable declaration and variable decrement or increment

Java code for implementing For loop 
1:  sum= 0;  
2:  for(i=0; i<100; i++) {  
3:  sum= sum + i;  
4:  };  
DLX code for implementing For loop 
1:       add r1, r0, r0      ; sum= 0  
2:       addi r2, r0, 0      ; i= 0  
3:  L1:  slti r3, r2, 100    ; is i<100?  
4:       bf r3, L2           ; No, exit loop  
5:       add r1, r1, r2      ; sum= sum+i  
6:       addi r2, r2, 1      ; i= i+1  increment loop, 
7:       j L1                ; jump back to L1 again untill condition satisfy
8:  L2   Jr 31               ; end of program


Tags:Implementing for loop on DLX Program,for loop on DLX Program,DLX programming

0 comments:

Post a Comment

Popular Posts