Advertisement
myersjo

Shift64

Dec 10th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.04 KB | None | 0 0
  1.     AREA    Shift64, CODE, READONLY
  2.     IMPORT  main
  3.     EXPORT  start
  4.  
  5. start
  6.     LDR R0, =0x13131313         ; least significant (LS) word
  7.     LDR R1, =0x13131313         ; most significant (MS) word   
  8.     LDR R2, =-2                 ; number of places to shift (n)
  9.     LDR R3, =0                  ; number of bits to shift to get bits which move between registers (n most/least significant bits)
  10.     LDR R4, =0                  ; tempValue - the bits which move between registers
  11.     LDR R5, =32                 ;
  12.    
  13.     CMP R2, #0                  ; if (n<0)
  14.     BLT shiftLeft               ;   go to shiftLeft
  15.    
  16. shiftRight 
  17.     SUB R3, R5, R2              ; 32-n
  18.     MOV R4, R1, LSL R3          ; tempValue
  19.     MOV R0, R0, LSR R2          ; move LS word right by n bits
  20.     ORR R0, R0, R4              ; add tempValue to beginning of LS word
  21.     MOV R1, R1, LSR R2          ; move MS word right by n bits
  22.     B stop
  23.    
  24. shiftLeft
  25.     SUB R2, R3, R2              ; |n| ; 0-(-n) = n
  26.     SUB R3, R5, R2              ; 32-n
  27.     MOV R4, R0, LSR R3          ; tempValue
  28.     MOV R1, R1, LSL R2          ; move MS word left by n bits
  29.     ORR R1, R1, R4              ; add tempValue to end of MS word
  30.     MOV R0, R0, LSL R2          ; move LS word left by n bits
  31.    
  32.    
  33. stop    B   stop
  34.  
  35.  
  36.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement