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