Showing posts with label Jump. Show all posts
Showing posts with label Jump. Show all posts

26 May 2013

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  

Popular Posts