20 Aug 2013

Perrin function Java to DLX Conversion



In this post we will look at how to convert java code into DLX code. We will create two functions Perrin and gensum .

The function P(n) computes the nth Perrin number. Perrin numbers are defined by the recursive rules:

P(0) = 3
P(1) = 0
P(2) = 2
P(n) = P(n-2) + P(n-3) for n > 2

So for example: -


  • P(0) returns 3
  • P(1) returns 0
  • P(2) returns 2
  • P(3) returns 3

  • The gensum function will return the sum of Perrin numbers from P(a) to P(b) using an increment of step.
    The range of the parameters are as follows:
    • 0 <= a <= b
    • step >=1
    If any of the parameters are out of range, the function must return -1.
    For example:
    • gensum(0, 5, 1) = P(0) + P(1) + P(2) + P(3) + P(4) + P(5) = 3 + 0 + 2 + 3 + 2 + 5 = 15
    • gensum(2, 11, 2) = P(2) + P(4) + P(6) + P(8) + P(10) = 2 + 2 + 5 + 10 + 17 = 36
    • gensum(5, 2, 1) = -1
    • gensum(2, 10, -1) = -1
    Java code for perrin and gensum


    1:  public class Perrin {  
    2:    private static int P(int n) {  
    3:      int a = 3, b = 0, c = 2; // the first three P(n)  
    4:      if (n==0)  
    5:      {  
    6:           return a;   
    7:      }  
    8:      else if (n==1){    
    9:        return b;  
    10:      }  
    11:      else if (n==2){   
    12:        return c;  
    13:      }  
    14:      else{  
    15:        int m = 0; //r2  
    16:        while (n > 2) {  
    17:          // System.out.println(n+" a"+a+" b"+b+" c"+c);  
    18:          m = a + b; //r2=r3+r4  
    19:          a = b;//r3=r4  
    20:          b = c;//r4=r5  
    21:          c = m;//r5=r2  
    22:          n=n-1;//r1=r1-1  
    23:         // System.out.println(n+" a"+a+" b"+b+" c"+c);  
    24:        }  
    25:        return m;  
    26:      }  
    27:    }  
    28:    private static int gensum(int a,int b,int step)  
    29:    {  
    30:         int sum=0;  
    31:         int p=0;  
    32:         for(int i=a;i<=b;i=i+step)  
    33:         {  
    34:              p=P(i);  
    35:              sum=sum+p;  
    36:              System.out.print(" i"+i+" p"+p+" "+sum+" ");  
    37:         }  
    38:         return sum;  
    39:    }  
    40:    public static void main(String[] args) {  
    41:      for (int i = 0; i < 21; i++)  
    42:        System.out.println("p(" + i + ")=" + P(i));  
    43:      System.out.println(gensum(0, 7, 1) );  
    44:    }  
    45:  }  
    

    DLX code Main DLX code
    1:  lights      .equ    16#FFFFFFF8  
    2:  switches    .equ    16#FFFFFFFC  
    3:       .start main  
    4:  main:       
    5:       add r1,r0,r0    ;a=0  
    6:       addi r3,r0,1    ;c=1  
    7:       lw r2,switches  ;b=switches input  
    8:       jal gensum      ;gensum(a,b,c)  
    9:       sw lights,r1    ;lights=result  
    10:      halt  
    
    Perrin function DLX code
    1:       P:                 ;P(x)       
    2:       sw r2backup,r2     ;result  
    4:       sw r3backup,r3     ;a  
    5:       sw r4backup,r4     ;b  
    6:       sw r5backup,r5     ;c  
    7:       sw r6backup,r6     ;If Result  
    8:                          ;Backup Registers End       
    9:        sequi r6,r1,0     ;x==0?  
    10:       bt r6,case0       ;if x=0 case0   
    11:       sequi r6,r1,1     ;x==1?  
    12:       bt r6,case1       ;if x=1 case1  
    13:       sequi r6,r1,2     ;x==2?  
    14:       bt r6,case2       ;if x=2 case2  
    15:       addi r2,r0,0      ;if x>2 result=0  
    16:       addi r3,r0,3      ;a=3  
    17:       addi r4,r0,0      ;b=0  
    18:       addi r5,r0,2      ;c=2  
    19: while sgti r6,r1,2      ;while(x>2)  
    20:       bf r6,case3       ;if while not true case3  
    21:        add r2,r3,r4     ;y = a + b  
    22:        add r3,r4,r0     ;a = b  
    23:        add r4,r5,r0     ;b = c  
    24:        add r5,r2,r0     ;c = y  
    25:        subi r1,r1,1     ;x=x-1  
    26:       j while           ;continue while loop  
    27:  case3   
    28:       addi r1,r2,0      ;result=y  
    29:       j endp       
    30:  case0   
    31:      addi r1,r0,3       ;r1=result=3  
    32:       j endp  
    33:  case1   
    34:      addi r1,r0,0       ;r1=result=0  
    35:      j endp  
    36:  case2   
    37:      addi r1,r0,2       ;r1=result=2  
    38:      j endp       
    39:  endp                   ;end of P Subroutine  
    40:                         ;Restore Registers Start  
    41:       lw r2,r2backup    
    42:       lw r3,r3backup  
    43:       lw r4,r4backup  
    44:       lw r5,r5backup  
    45:       lw r6,r6backup    
    46:                           ;Restore Registers End  
    47:         jr r31            ; end P            
    48:  r2backup .word 1000  
    49:  r3backup .word 1004  
    50:  r4backup .word 1008  
    51:  r5backup .word 1012  
    52:  r6backup .word 1016  
    
    Gensum function in DLX code
    1:  gensum:                  ;gensum(a,b,c)  
    2:                           ;Backup Registers Start  
    3:       sw r2backupG,r2     ;b  
    4:       sw r3backupG,r3     ;c  
    5:       sw r4backupG,r4     ;result of IF   
    6:       sw r5backupG,r5     ;sum  
    7:       sw r6backupG,r6     ;result of P Subroutine  
    8:       sw r7backupG,r7     ;i  
    9:       sw r8backupG,r8     ;backup r31 register  
    10:                           ;Backup Registers End  
    11:       slt r4,r1,r0      ;a<0?  
    12:       bt r4,errorcase   ;if true,errorcase  
    13:       slt r4,r2,r0      ;b<0?  
    14:       bt r4,errorcase   ;if true,errorcase  
    15:       slti r4,r3,1      ;step<1?  
    16:       bt r4,errorcase   ;if true,errorcase  
    17:       sle r4,r2,r1      ;a<b?  
    18:       bt r4,errorcase   ;if true,errorcase  
    19:       addi r5,r0,0      ;sum=0  
    20:       addi r6,r0,0      ;result of P=0  
    21:       add r7,r0,r1      ;i=a  
    22:  for  slt r4,r2,r7      ;i<b for (i=a;i<b;i=i+step)  
    23:       bt r4,endfor      ;end for loop  
    24:       add r1,r0,r7      ;a=i  
    25:       add r8,r31,r0     ;backup r31 register  
    26:       jal P             ;P(i)  
    27:       add r31,r8,r0     ;restore r31 register  
    28:       add r5,r5,r1      ;sum=sum+P(i)  
    29:       add r7,r7,r3      ;i=i+step  
    30:       j for                 
    31:  endfor  
    32:       add r1,r5,r0     ;a=sum  
    33:       sw result,r1     ;result=sum  
    34:       j endgensum  
    35:  errorcase  
    36:    addi r1,r0,-1       ;a=-1  
    37:       j endgensum  
    38:  endgensum  
    39:                        ;Restore Registers Start  
    40:       lw r2,r2backupG  
    41:       lw r3,r3backupG                      
    42:       lw r4,r4backupG  
    43:       lw r5,r5backupG  
    44:       lw r6,r6backupG   
    45:       lw r7,r7backupG       
    46:       lw r8,r8backupG  
    47:                           ;Restore Registers End  
    48:       jr r31              ;end gensum()  
    49:  r2backupG .word 2000  
    50:  r3backupG .word 2004  
    51:  r4backupG .word 2008  
    52:  r5backupG .word 2012  
    53:  r6backupG .word 2016  
    54:  r7backupG .word 2020  
    55:  r8backupG .word 2024  
    56:  result      .word      2028  
    
    Tags:Example DLX program,Perrin function,gensum function,DLX code

    14 Jul 2013

    Division in DLX programming

    When we multiply or divide unsigned numbers, we must use logical shifts, as we will now see.

    Example 1

      addui r1,r0,200   
      srli r2,r1,1 ;2^1  
      ;r2=200/2=100  
    
    Example 2
      addui r1,r0,200   
      srli r2,r1,2 ;2^2  
      ;r2=200/4=50  
    
    Example 3
      addui r1,r0,200   
      srli r2,r1,3 ;2^3  
      ;r2=200/8=25  
    
    Tags:Division in DLX programming,Divide instruction on DLX,DLX divide function

    Multiplication in DLX programming


    When we multiply or divide unsigned numbers, we must use logical shifts, as we will now see.We can multiply 2 the power values by just shifting bits in left 

    Example multiply by 2

     addui r1,r0,25  
     slli r2,r1,1  ;2^1
     ;r2=25X2=50  
    

    Example multiply by 4
     addui r1,r0,25  
     slli r2,r1,2  ;2^2
     ;r2=25X4=100  
    

    Example multiply by 8
     addui r1,r0,25  
     slli r2,r1,3  ;2^3
     ;r2=25X8=200  
    


    Tags:Multiplication on dlx, Multiply registers in DLX, DLX Multiplication

    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

    DLX OR & OR-immediate instructions


    The or instruction takes the 32-bit data value in register source1 and performs a logical-or operation
    between it and the 32-bit value in register source2 , then puts the result in register destination register. 
    The operation iscarried out between corresponding bits of the two operands. The ori instruction is similar, except that the second operand is the 16-bit unsigned immediate value Kuns, zero-extended to 32 bits.


    Source 1 and Source 2 =Destination register

    Example:

    r1=Source1
    r2=Source2
    r3=Source3

    r1r2r3
    000
    011
    101
    111
    OR instruction used to set certain or all bits 1

    Example to make last 4 digits to 1 and leave the remaining to original values

    r111010011
    r200001111
    r311001111
    r2=We are interested in last 4 bits so we make last 4 digits to one and rest of them to zero
    r3=first 4 digits are followed from source and last 4 digits set to 1


    DLX And and ORI Instrunction

    or r3,r1,r2
    if r1 or r2 or equal to 1 then 1 else 0
    ori r3,r1,1
    r3 will be 1
    ori r3,r1,0
    r3 =r1

    Tags:OR  instruction, OR-immediate instructions,DLX or instruction, DLX ORI instruction


    DLX And & And-immediate instructions

    The and instruction takes the 32-bit data value in register source1 and performs a logical-and operation
    between it and the 32-bit value in register source2, then puts the result in register destination register. The and operation is carried out between corresponding bits of the two operands.

    Source 1 and Source 2 =Destination register

    Example:

    r1=Source1
    r2=Source2
    r3=Source3


    r1 r2 r3
    0 0 0
    0 1 0
    1 0 0
    1 1 1


    And instruction can be used for masking to allow only certain bits

    Example

    If we are interested in last 4 digits of r1 register then create marking like below

    r1 1 1 0 1 0 0 1 1
    r2 0 0 0 0 1 1 1 1
    r3 0 0 0 0 0 0 1 1


    r2=We are interested in last 4 bits so we make last 4 digits to one and rest of them to zero
    r3=first 4 digits are zero and last 4 digits followed r1 last 4 digits


    DLX And and ANDI Instrunction

    and r3,r1,r2
    if r1 and r2 or equal then r3 will be 1 else r3 will be 0
    andi  r3,r1,1
    if r1 is 1 then r3 will be 1 else r3 will be 0


    Tags:And instruction, And-immediate instructions,DLX and instruction, DLX Andi instruction

    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

    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

    Running DLX Simulator


    1,Command to execute simulator
    java -jar Dsim.jar

    2,DLX Simulator















    3,Loading DLX file into DSIM simulator
















    4,Registers view, DLX Cpu >>Register








    5, Ram View, Ram >Viewer


















    6,Lights view, Lights>Lights






    7,Switches view ,Switches >switches






    Ram,Lights,Switches depends on DSIM.cfg file.

    Tags:Running DLX Simulator ,DLX GUI, DLX Switches,DLX Lights,DLX Ram,DLX Switches,DLX Registers

    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

    Assembly and running your program

    1,Create new folder ,example: dlx in D ,D:\dlx
    2,Copy dasm.jar,dsim.jar,dsim.cfg to dlx folder
    3,Create dls program, Ex try.dls
    4,Assemble your program using this command
    java -jar dasm.jar -a try.dls
    5,After executing this command,It will create try.dlx on dlx folder
    6,Run this dlx file using this command
    java -jar Dsim.jar


    Introduction to DLX Machine

    DLX Machine architecture




















    • DLX machine consists of 32 registers from r0 to r31
    r0 always 0
    r31 Jr Register
    r1 to r30 can be used for program

    • DLX machine RAM depends on dsim.cfg file
    dsim.cfg file contains.

    dsim new bus dsim.bus.Bus 

    dsim new cpu dsim.dlxcpu.Dlxcpu
    dsim connect bus$slot0 cpu$dlxbus

    dsim new ram dsim.ram.Ram 00000 4000
    dsim connect bus$slot2 ram$dlxbus

    In this case, DLX machine consist of Ram upto 4000 from 0 (Ex 0,4,8,12..4000)


    • DLX machine consists of IO Devices includes switches and lights
    Address of lights and switches depends on dsim.cfg file


    dsim new lights dsim.lights.Lights FFFFFFF8
    dsim connect bus$slot1 lights$dlxbus

    dsim new switches dsim.switches.Switches FFFFFFFC
    dsim connect bus$slot3 switches$dlxbus


    Address for lights      :FFFFFFF8
    Address for switches:FFFFFFFC


    Popular Posts