Difference between revisions of "Shift left"
From Unofficial QEdit Wiki Guide
Line 8: | Line 8: | ||
Used to execute a logical bitwise operation shift left. Use [[shift_right]] to shift right.<br /> | Used to execute a logical bitwise operation shift left. Use [[shift_right]] to shift right.<br /> | ||
In the example below we'll use R1 to store a 7Bit value 100 decimal (127 decimal value maximum) and 2 seperate flags set true.<br /> | In the example below we'll use R1 to store a 7Bit value 100 decimal (127 decimal value maximum) and 2 seperate flags set true.<br /> | ||
− | 1100100 = 100 Decimal | + | 1100100 = 100 Decimal |
− | 1 = Flag 1 true | + | 1 = Flag 1 true |
− | 1 = Flag 2 true | + | 1 = Flag 2 true |
Value to store 00000000000000000000000110010011 (403 decimal, 193 hex) | Value to store 00000000000000000000000110010011 (403 decimal, 193 hex) | ||
Line 18: | Line 18: | ||
<span style='color:green'> let </span>R2, R1 <span style='color:orange'>//This will be used for 7bit value</span> | <span style='color:green'> let </span>R2, R1 <span style='color:orange'>//This will be used for 7bit value</span> | ||
<span style='color:green'> leti </span>R5, 00000002 <span style='color:orange'>//This will be used to store the SHIFT amount</span> | <span style='color:green'> leti </span>R5, 00000002 <span style='color:orange'>//This will be used to store the SHIFT amount</span> | ||
− | <span style='color:green'> andi </span>R2, 000001FC <span style='color:orange'>//Perform bitwise AND operation on R2 using 00000000000000000000000111111100 binary. R2 now equals 00000000000000000000000110010000</span> | + | <span style='color:green'> andi </span>R2, 000001FC <span style='color:orange'>//Perform bitwise AND operation on R2 using 508 (00000000000000000000000111111100 binary). R2 now equals 400 (00000000000000000000000110010000)</span> |
<span style='color:green'> shift_right </span>R2, R5 <span style='color:orange'>//Perform bitwise SHIFT RIGHT on R2. Value changed from 400 (00000000000000000000000110010000) to 100 (00000000000000000000000001100100)</span> | <span style='color:green'> shift_right </span>R2, R5 <span style='color:orange'>//Perform bitwise SHIFT RIGHT on R2. Value changed from 400 (00000000000000000000000110010000) to 100 (00000000000000000000000001100100)</span> | ||
<span style='color:green'> let </span>R3, R1 <span style='color:orange'>//This will be used to store the first flag</span> | <span style='color:green'> let </span>R3, R1 <span style='color:orange'>//This will be used to store the first flag</span> | ||
Line 28: | Line 28: | ||
<span style='color:green'> ret </span> | <span style='color:green'> ret </span> | ||
</span> | </span> | ||
+ | |||
+ | R2 Now equals 100, R3 equals 1 (true), R4 equals 1 (true). Now to change the values and store them back in R1.<br /> | ||
==Also see== | ==Also see== | ||
List of OP Codes used in example. | List of OP Codes used in example. |
Revision as of 16:31, 5 May 2011
Contents
Syntax
Syntax: shift_left register1, register2
- register1 = Register to shift left
- register2 = Shift left by value of register2
Use
Used to execute a logical bitwise operation shift left. Use shift_right to shift right.
In the example below we'll use R1 to store a 7Bit value 100 decimal (127 decimal value maximum) and 2 seperate flags set true.
1100100 = 100 Decimal 1 = Flag 1 true 1 = Flag 2 true Value to store 00000000000000000000000110010011 (403 decimal, 193 hex)
Example
100: leti R1, 00000193 //Set R1 to 403 (00000000000000000000000110010011 in binary)
let R2, R1 //This will be used for 7bit value
leti R5, 00000002 //This will be used to store the 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
andi R3, 00000001 //Perform bitwise AND operation on R2 using 00000000000000000000000000000001 binary. R2 now equals 1
let R4, R1 //This will be used to store the second flag
leti R5, 00000001 //This will be used to store the SHIFT amount
andi R4, 00000002 //Perform bitwise AND operation on R4 using 00000000000000000000000000000010 binary. R2 now equals 2
shift_right R4, R5 //Perform bitwise SHIFT RIGHT on R4. Value changed from 2 (00000000000000000000000000000010) to 1 (00000000000000000000000000000001)
ret
R2 Now equals 100, R3 equals 1 (true), R4 equals 1 (true). Now to change the values and store them back in R1.
Also see
List of OP Codes used in example.