Difference between revisions of "Shift left"

From Unofficial QEdit Wiki Guide
Jump to: navigation, search
 
(8 intermediate revisions by the same user not shown)
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 one set true the other set false.<br />
 
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.<br />
  1100100 = 100 Decimal
+
<br />
  1 = Flag 1 true
+
  From:
  0 = Flag 2 false
+
<b><span style='color:blue'>1100100</span></b> = 100 Decimal
  Value to store 00000000000000000000000110010010 (402 decimal, 192 hex)
+
  <b><span style='color:red'>1</span></b> = Flag 1 true
 +
  <b><span style='color:green'>0</span></b> = Flag 2 false
 +
  Value to store 00000000000000000000000<b><span style='color:blue'>1100100</span><span style='color:red'>1</span><span style='color:green'>0</span></b> (402 decimal, 192 hex)
 +
 +
To:
 +
<b><span style='color:blue'>0110010</span></b> = 50 Decimal
 +
<b><span style='color:red'>0</span></b> = Flag 1 False
 +
<b><span style='color:green'>1</span></b> = Flag 2 True
 +
Value to store 00000000000000000000000<b><span style='color:blue'>0110010</span><span style='color:red'>0</span><span style='color:green'>1</span></b>(201 decimal, C9 hex)
  
 
==Example==
 
==Example==
 
  <span style='font-size:12px;font-family:courier'>
 
  <span style='font-size:12px;font-family:courier'>
  <span style='color:blue'>100:    </span><span style='color:green'>leti </span>R1, 00000192 <span style='color:orange'>//Set R1 to 403 (00000000000000000000000110010010 in binary)</span>
+
  <span style='color:blue'>100:    </span><span style='color:green'>leti </span>R1, 00000192 <span style='color:orange'>//Set R1 to 402 (00000000000000000000000110010010 in binary)</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'>        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'>//Set R5 to SHIFT AMOUNT</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'>        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>
Line 38: Line 46:
 
  <span style='color:green'>        let </span>R1, R2 <span style='color:orange'>//Set R1 to R2 (50)</span>
 
  <span style='color:green'>        let </span>R1, R2 <span style='color:orange'>//Set R1 to R2 (50)</span>
 
  <span style='color:green'>        shift_left </span>R1, R5 <span style='color:orange'>//Perform bitwise SHIFT LEFT on R1. Value changed from 50 (00000000000000000000000000110010) to 100 (00000000000000000000000001100100)</span>
 
  <span style='color:green'>        shift_left </span>R1, R5 <span style='color:orange'>//Perform bitwise SHIFT LEFT on R1. Value changed from 50 (00000000000000000000000000110010) to 100 (00000000000000000000000001100100)</span>
  <span style='color:green'>        or </span>R1, R3 <span style='color:orange'>//Perform bitwise OR operation on R4 using R3 (00000000000000000000000000000000). R1 now equals 100</span>
+
  <span style='color:green'>        or </span>R1, R3 <span style='color:orange'>//Perform bitwise OR operation on R1 using R3 (00000000000000000000000000000000). R1 still equals 100</span>
  <span style='color:green'>        shift_left </span>R1, R5 <span style='color:orange'>//Perform bitwise SHIFT LEFT on R1. Value changed from 100 (00000000000000000000000001100100) to 100 (00000000000000000000000001100100)</span>
+
  <span style='color:green'>        shift_left </span>R1, R5 <span style='color:orange'>//Perform bitwise SHIFT LEFT on R1. Value changed from 100 (00000000000000000000000001100100) to 200 (00000000000000000000000011001000)</span>
 +
<span style='color:green'>        or </span>R1, R4 <span style='color:orange'>//Perform bitwise OR operation on R1 using R4 (00000000000000000000000000000001). R1 now equals 201 (00000000000000000000000011001001)</span>
 
  <span style='color:green'>        ret </span>
 
  <span style='color:green'>        ret </span>
 
  </span>
 
  </span>
 +
 
==Also see==
 
==Also see==
List of OP Codes used in example.
+
[[shift_right]], [[leti]], [[let]], [[andi]], [[or]], [[ret]]

Latest revision as of 16:15, 6 May 2011

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 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_right, leti, let, andi, or, ret