1 Jun 2013

Using If and Else statement on DLX program




Implementing If else Conditional statement on DLX Program

Example Java code to implement IF& Else
1:  if (x<0) {  
2:  y= 0;  
3:  }else{  
4:  y= x;  
5:  }  

DLX Program conversion

1:  lw r1, x           ; r1= x  
2:  slt r2, r1, r0     ; is x < 0?  
3:  bf r2, L1          ; No, skip “then” part  
4:  add r2, r0, r0     ; Yes, r2 =0  
5:  j L2               ; skip “else” part  
6:  L1: add r2, r0, r1 ; r2 = x  
7:  L2: sw Y, r2       ; y = r2  
Tags:DLX if statement,DLX else statement, DLX If& else,DLX conditional statement, DLX sample program

1 comment:

Popular Posts