Shift right

From Unofficial QEdit Wiki Guide
Jump to: navigation, search

Syntax

Syntax: shift_right register1, register2

  • register1 = Register to shift right
  • register2 = Shift right by value of register2

Use

Used to execute a logical bitwise operation shift right. Use shift_left to shift left.
In the example below we'll use R1 to store a 7Bit value 100 decimal (127 decimal value maximum) and 2 seperate flags one set true the other set false.

From:
1100100 = 100 Decimal
1 = Flag 1 true
0 = Flag 2 false
Value to store 00000000000000000000000110010010 (402 decimal, 192 hex)

To:
0110010 = 50 Decimal
0 = Flag 1 False
1 = Flag 2 True
Value to store 00000000000000000000000011001001(201 decimal, C9 hex)

Example


100:     leti R1, 00000192 //Set R1 to 402 (00000000000000000000000110010010 in binary)
         let R2, R1 //This will be used for 7bit value
         leti R5, 00000002 //Set R5 to SHIFT AMOUNT
         andi R2, 000001FC //Perform bitwise AND operation on R2 using 508 (00000000000000000000000111111100 binary). R2 now equals 400 (00000000000000000000000110010000)
         shift_right R2, R5 //Perform bitwise SHIFT RIGHT on R2. Value changed from 400 (00000000000000000000000110010000) to 100 (00000000000000000000000001100100)
         let R3, R1 //This will be used to store the first flag
         leti R5, 00000001 //This will be used to store the SHIFT amount
         andi R3, 00000002 //Perform bitwise AND operation on R3 using 00000000000000000000000000000010 binary. R2 now equals 2
         shift_right R3, R5 //Perform bitwise SHIFT RIGHT on R3. Value changed from 2 (00000000000000000000000000000010) to 1 (00000000000000000000000000000001)
         let R4, R1 //This will be used to store the second flag
         andi R4, 00000001 //Perform bitwise AND operation on R2 using 00000000000000000000000000000001 binary. R2 now equals 0
         ret 

R2 Now equals 100, R3 equals 1 (true), R4 equals 0 (false). Now to change the values and store them back in R1.


200:     leti R2, 00000032 //Set R2 to 50
         leti R3, 00000000 //Set R3 to 0 (false)
         leti R4, 00000001 //Set R4 to 1 (true)
         leti R5, 00000001 //Set R5 to SHIFT AMOUNT
         let R1, R2 //Set R1 to R2 (50)
         shift_left R1, R5 //Perform bitwise SHIFT LEFT on R1. Value changed from 50 (00000000000000000000000000110010) to 100 (00000000000000000000000001100100)
         or R1, R3 //Perform bitwise OR operation on R1 using R3 (00000000000000000000000000000000). R1 still equals 100
         shift_left R1, R5 //Perform bitwise SHIFT LEFT on R1. Value changed from 100 (00000000000000000000000001100100) to 200 (00000000000000000000000011001000)
         or R1, R4 //Perform bitwise OR operation on R1 using R4 (00000000000000000000000000000001). R1 now equals 201 (00000000000000000000000011001001)
         ret 

Also see

shift_left, leti, let, andi, or, ret