#### Mike Chambers

##### Veteran Member

- Joined
- Sep 2, 2006

- Messages
- 2,621

Code:

```
Sub op_grp2(ByVal word)
Dim signval, bits, maxval, oldcf as UInteger
If oper2 = 0 Then Exit Sub
If word Then signval = 32768: maxval = 65535: bits = 16 Else signval = 128: maxval = 255: bits = 8
Select Case reg
Case 0 'ROL
temp1 = (oper1 Shl (oper2 And (bits-1))) Or (oper1 Shr (bits - (oper2 And (bits-1))))
cf = temp1 And 1
of = ((temp1 Shr (bits-1)) Xor temp1) And 1
Case 1 'ROR
temp1 = (oper1 Shr (oper2 And (bits-1))) Or (oper1 Shl (bits - (oper2 And (bits-1))))
cf = ((temp1 And signval) \ signval) And 1
If oper2 = 1 Then of = (((temp1 Xor oper1) And signval) \ signval) And 1
Case 2 'RCL
oper1 = oper1 Or (cf Shl bits)
temp1 = (oper1 Shl (oper2 Mod (bits+1))) Or (oper1 Shr ((bits+1) - (oper2 Mod (bits+1))))
cf = ((temp1 and (maxval+1)) \ (maxval+1)) And 1
of = ((((temp1 Shr 1) Xor temp1) And signval) \ signval) And 1
Case 3 'RCR
oper1 = oper1 Or (cf Shl bits)
temp1 = (oper1 Shr (oper2 Mod (bits+1))) Or (oper1 Shl ((bits+1) - (oper2 Mod (bits+1))))
cf = ((temp1 And (maxval+1)) \ (maxval+1)) And 1
If oper1 = 1 Then of = (((temp1 Xor oper1) And signval) \ signval) And 1
Case 4, 6 'SHL/SAL
If (oper2 > bits) Then temp1 = 0 Else temp1 = oper1 Shl oper2
If word Then flag_szp16 temp1 Else flag_szp8 temp1
cf = ((temp1 And (maxval+1)) \ (maxval+1)) And 1
of = ((((temp1 Shr 1) Xor temp1) And signval) \ signval) And 1
Case 5 'SHR
If (oper2 > bits) Then temp1 = 0 Else temp1 = (oper1 Shr (oper2 - 1))
cf = temp1 And 1
temp1 = temp1 Shr 1
If word Then flag_szp16 temp1 Else flag_szp8 temp1
of = ((((temp1 Shl 1) Xor temp1) And signval) \ signval) And 1
Case 7 'SAR
If word Then temp1 = &hFFFF0000& Else temp1 = &hFF00&
If (oper1 And signval) = signval Then oper1 = oper1 Or temp1
If (oper2 >= bits) Then temp1 = oper1 Shr (bits - 1) Else temp1 = oper1 Shr (oper2-1)
cf = temp1 And 1
temp1 = (temp1 Shr 1) And maxval
If word Then flag_szp16 temp1 Else flag_szp8 temp1
of = 0
End Select
result = temp1 And maxval
End Sub
```