2 Jun 2013

Shift left and Shift right instruction on DLX Program



Shift left and Shift right instruction are used to move bits in a register ,This will used for multiplication and division of registers.

Example Shift left DLX program

1:  ;before execution r1=3=0000 0011  
2:  ;before execution r2=0=0000 0000  
3:       .start main  
4:  main:  
5:       addi r1,r0,3 ;r1=3  
6:       slai r2,r1,2 ;move 2 bits left from R1 and save it to R2  
7:       halt  
8:  ;After execution r1=3=0000 0011  
9:  ;After execution r2=0=0000 1100  

Example Shift Right DLX program

1:  ;before execution r1=2=0000 0010  
2:  ;before execution r2=0=0000 0000  
3:       .start main  
4:  main:  
5:       addi r1,r0,2 ;r1=2  
6:       srai r2,r1,1  ;move 2 bits right from R1 and save it to R2  
7:       halt  
8:  ;After execution r1=2=0000 0010  
9:  ;After execution r2=1=0000 0001  


Shift DLX program commands

Shift right Arithmatic
sra rk,ri,rj rk
Shift right Arithmatic Immediate
srai rj,ri,u rj
Shift right Logical
srl rk,ri,rj rk
Shift right logical Immediate
srli rj,ri,u rj
Shift Left Arithmatic
sla rk,ri,rj rk
Shift Left Arithmatic Immediate
slai rj,ri,u rj
Shift light Logical
sll rk,ri,rj rk
Shift light Logical immediate
slli rj,ri,u rj

Tags:Shift left and Shift right instruction on DLX Program,Shift left DLX,Shift Right DLX,DLX program

1 Jun 2013

DLS file layout and comments



Following format shows, how to write DLS file.

Usually program start with ".start" and following line with subroutine name

Semicolon (;) used for comments and used in end of the statements

Label         Opcode       Operands      Comments
L1               add             r1,r0,r1           ;r1++


Memory address declaration

Label:            .word    exp1
r1backup       .word    4
r1backup   reference pointer for memory address 4

Allocating empty space on DLX program

Label:      .space     expr
Array:      .space       40      ;Allocate 10 words 

Setting the program start address
                 .start expr

Example
                 .start Main ;Jump to Main
Array: .space 10*4
Index: .word 0
Main: lw r1, Index      ;Jump to here



Tags:DLS file layout and comments,DLS file layout,DLS file commands,DLX file







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

Implementing While loop on DLX Program

Implementing While loop on DLX Program 

While loop Java Code
1:  int i=0;  
2:  while (x>2)  
3:  {  
4:  i=i+1;  
5:  }  
While loop in DLX program
1:  while  sgti r6,r1,2  ;while(x>2)  
2:        bf r6,ew       ;if while not true ew   
3:      addi r1,r1,1     ;i++  
4:       j while         ;Jump to while  
5:  ew     Jr31          ;End of program  
Tags:Implementing While loop on DLX Program,While loop on DLX Program,While command on DLX

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

Comparing registers on DLX program

List of comparison commands on DLX program

Signed numbers Comparison
  • Set Less than
slt rd, rs1, rs2 ; set rd to 1 if rs1 < rs2, otherwise set rd to 0
  • Set Less than or equal
sle rd, rs1, rs2 ; set rd to 1 if rs1 ≤ rs2, otherwise set rd to 0
  • Set Greater than
sgt rd, rs1, rs2 ; set rd to 1 if rs1 > rs2, otherwise set rd to 0
  • Set Greater than or eual
sge rd, rs1, rs2 ; set rd to 1 if rs1 ≥ rs2, otherwise set rd to 0


Unsigned numbers Comparison 


  • Set Less than -Unsigned
sltu rd, rs1, rs2 ; set rd to 1 if rs1 < rs2, otherwise set rd to 0
  • Set Less than or equal -Unsigned
sleu rd, rs1, rs2 ; set rd to 1 if rs1 ≤ rs2, otherwise set rd to 0
  • Set Greater than -Unsigned
sgtu rd, rs1, rs2 ; set rd to 1 if rs1 > rs2, otherwise set rd to 0
  • Set Greater than or eual -Unsigned
sgeu rd, rs1, rs2 ; set rd to 1 if rs1 ≥ rs2, otherwise set rd to 0

Check condtition result register rd by using branch true or branch false Instuction



Tags:DLX programming, DLX Comparison,DLX Arithmatic Comparison, DLX If Statement

Popular Posts