Showing posts with label Commands. Show all posts
Showing posts with label Commands. Show all posts

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

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

27 May 2013

Check two registers for equal/not equal on DLX program


DLX provides two instructions for comparing numbers:

  1. seq (set if equal)
  2. sne (set if not equal).
Seq instruction example:
Seq result register,compare1 register,compare2 register
Result register will be 1 if the registers are equal otherwise 0
Use branch true (bt) or branch false (bf) to compare result register


1:  seq r1,r2,r4 ;Checks if r2=r4  
2:  bt r1,L1 ; if true (Branch true ) Jump to L1  
3:  <OtherStatements> ;If false execute this  
4:  jr r31 ;end program  
5:  L1 ;Jump to here if condition fails  
6:  jr r31 ;end program  

Sne instruction example: 
Sne result register,compare1 register,compare2 register
Result register will be 1 if the registers are not equal otherwise 0
Use branch true (bt) or branch false (bf) to compare result register

1:  sne r1,r2,r4 ;Checks if r2=!r4  
2:  bt r1,L1 ; if true (Branch true ) Jump to L1  
3:  <OtherStatements> ;If false execute this  
4:  jr r31 ;end program  
5:  L1 ;Jump to here if condition fails  
6:  jr r31 ;end program  

26 May 2013

Halt Instruction on DLX Program

Halt is a command is equal to Stop or pause .
Once executed ,DLX program need to re run again 

Formal Description:
When this instruction is executed, the processor ceases fetching and executing instructions. A halted processor can only be restarted by some means external to the processor, such as a reset button.

Example code.

 halt  

Jump to Subroutine & Jump Return instruction on DLX Program


Jump to Subroutine & Jump Return instruction on DLX Program

Example code
Jal subroutine name
Sub routine
Jr r31 to return to main program

Example Jump to Subroutine & Jump Return instruction on DLX Program 


  .start main ;Start program and jump to label main  
 main:       
 jal calculator;jump and link to calculator  
 halt ; halt program after executing calculator sub routine  
 calculator: ;calculator sub routine  
 add r1,r2,r3  
 jr r31 ;back to main method and execute halt statement  

Unconditional Jump on DLX Program


Jump Instruction used for skipping some portion of sequential program

Jump instruction can be used conditional statements like IF,While,For

Example Jump DLX code 1

 j End;Jump to label End  
 add r1,r2,r3  ;Skip this command  
 End  ;label end  
 jr r31  
Example Jump DLX code 2
 add r1,r1,r2  
 j end;Jump to end label  
 sub r1,r0,r1 ;Never gets here...  
 subi r2,r2,2  
 end addi r1,r1,1  

Subtract two Values in DLX Programming

Subtraction commands on DLX

1:  sub r1,r2,r3   ;Subtract Signed integers  
2:  subi r1,r2,100 ;Subtract Signed integers Immediate  
3:  subur1,r2,r3   ;Subtract Unsigned integers  
4:  subui r1,r2,100;Subtract Unsigned integers Immediate  
Explanation of code for subtracting from 2 registers
1:  ; #r1 register=0  
2:  ; #r2 register=10  
3:  ; #r3 register=30  
4:  ; Before execution  
5:  sub r1,r2,r3  
6:  ; After execution  
7:  ; #r1 register=20  
8:  ; #r2 register=10  
9:  ; #r3 register=30  
Explanation of code for subtracting register from immediate value
1:  ; #r1 register=0  
2:  ; #r2 register=10  
3:  ; Before execution  
4:  subi r1,r2,30  
5:  ; After execution  
6:  ; #r1 register=20  
7:  ; #r2 register=10  

Adding two Integer values in DLX



Adding two Integers from two Registers Example code:
1:  Add r1,r2,r3 ;r1=r2+r3  
Explanation of code:
1:  #r1 register=0  
2:  #r2 register=1  
3:  #r3 register=2  
4:  //before execution  
5:  Add r1,r2,r3 ;r1=r2+r3  
6:  //after execution  
7:  #r1 register=3  
8:  #r2 register=1  
9:  #r3 register=2  


Adding a register with immediate value Example code
1:  addi r1,r2,100  
Explanation of code
1:  #r1 register=0  
2:  #r2 register=1  
3:  //before execution  
4:  addi r1,r2,100  
5:  //after execution  
6:  #r1 register=101  
7:  #r2 register=1  



Addition Commands on DLX
1:  add r1,r2,r3   ;Adding Signed integers  
2:  addi r1,r2,100 ;Adding Signed integers Immediate  
3:  addu r1,r2,r3   ;Adding Unsigned integers  
4:  addui r1,r2,100 ;Adding Unsigned integers Immediate  

25 May 2013

Loading and Storing Value to DLX Ram from Registes

DLX Code
1:  lw r5,16#100  
2:  sw 16#200,r5  
Explanation DLX Code
1:  # Ram 100=0  
2:  r5 register=8  
3:  sw 16#100,r5 //Copy r5 resgiter value to memory 100  
4:  r5 register=8  
5:  # Ram 100=8  
6:  lw r5,16#100 //Copy memory into r5 register  
7:  # Ram 100=8  
8:  r5 register=8  
Tags:Loading Storing DLX registers, Backup DLX Registers,Copy ram to Register on DLX

DLS file and DLX file and commands

DLS file is Source file
File created by user and Input of Assembler DSAM

DLX file is Executable file
File created by Assembler if the file assemble. It can be run from DLX simulator

>>java -jar dasm.jar  try.dls -a
-a Program follows absolute address

>>java -jar dasm.jar  try.dls -a -l
-l List down the error & assembly of your program

>>java -jar Dsim.jar
To run simulator

Popular Posts