14 Jul 2013

Example DLX program to sum of integers


Here is the Example DLX program to sum of integers 

Java version

 sum= 0;  
 j= 100;  
 for( i=0; i<100; i++ ){  
 if( i>j ){  
 sum= sum+i;  
 }else{  
 sum= sum+j;  
 }  
 j--;  
 }  
DLX Code

In DLX program we need to assign registers for each variables.

r4=temp register to store result
r3=Sum
r2=j
r1=i
      add r3,r0,r0 ;sum= 0;  
      addi r2,r0,100 ;Init j  
      addi r1,r0,0 ;Init i  
 L1   slti r4,r1,100 ;i<100?  
      bf r4,L4 ;No  
      sgt r4,r1,r2 ;i>j?  
      bf r4,L2 ;No  
      add r3,r3,r1 ;Yes, sum= sum+i  
      j L3  
 L2   add r3,r3,r2 ;sum= sum+j  
 L3   subi r2,r2,1 ;j= j-1  
      addi r1,r1,1 ;i= i+1;  
      j L1  
 L4   halt
Tags: sum of integers,DLX Example program,Simple DLX program

0 comments:

Post a Comment

Popular Posts