ManchesterCode
SwordfishUser.ManchesterCode History
Hide minor edits - Show changes to output
Deleted lines 0-9:
*[[#C1 | Swordfish BASIC]] - %newwin%[[http://www.sfcompiler.co.uk | Mecanique]]
*[[#C2 | CCS C]] - %newwin%[[http://www.ccsinfo.com | Custom Computer Services, Inc]]
*[[#C3 | MikroElectronika BASIC]] - %newwin%[[http://www.mikroe.com | MikroElectronika]]
*[[#C4 | PROTON BASIC]]- %newwin%[[http://www.picbasic.org | Crownhill]]
*[[#C5 | PicBASIC PRO]]- %newwin%[[http://www.melabs.com | microEngineering Labs]]
The code itself is not intended to be optimised in any way. However, each implementation is intended to match as closel as possible the original Swordfish version.
Changed lines 1-2 from:
The following is the reference sample code used when evaluating different compilers.
to:
The following sample code was used to evaluate different compilers.
Changed lines 3-11 from:
*[[#C1 | Swordfish BASIC]]
*[[#C2 | CCS C]]
*[[#C3 | MikroElectronika BASIC]]
*[[#C4 | Crownhill PROTON BASIC]]
*[[#C5 | microEngineering Labs PicBASIC PRO]]
The code itself is not intended to be optimised in any way. However, each implementation mirrors the Swordfish version as close as is possible with the particular language used.
!!! [[#C1]]Swordfish BASIC
*
*[[#
The code itself is not intended to be optimised in any way. However, each implementation mirrors the Swordfish version as close as is possible with the particular language used.
!!! [[#C1]]Swordfish BASIC
to:
*[[#C1 | Swordfish BASIC]] - %newwin%[[http://www.sfcompiler.co.uk | Mecanique]]
*[[#C2 | CCS C]] - %newwin%[[http://www.ccsinfo.com | Custom Computer Services, Inc]]
*[[#C3 | MikroElectronika BASIC]] - %newwin%[[http://www.mikroe.com | MikroElectronika]]
*[[#C4 | PROTON BASIC]]- %newwin%[[http://www.picbasic.org | Crownhill]]
*[[#C5 | PicBASIC PRO]]- %newwin%[[http://www.melabs.com | microEngineering Labs]]
The code itself is not intended to be optimised in any way. However, each implementation is intended to match as closel as possible the original Swordfish version.
!!! [[#C1]]Swordfish
*[[#C2 | CCS C]] - %newwin%[[http://www.ccsinfo.com | Custom Computer Services, Inc]]
*[[#C3 | MikroElectronika BASIC]] - %newwin%[[http://www.mikroe.com | MikroElectronika]]
*[[#C4 | PROTON BASIC]]- %newwin%[[http://www.picbasic.org | Crownhill]]
*[[#C5 | PicBASIC PRO]]- %newwin%[[http://www.melabs.com | microEngineering Labs]]
The code itself is not intended to be optimised in any way. However, each implementation is intended to match as closel as possible the original Swordfish version.
!!! [[#C1]]Swordfish
Changed line 193 from:
!!! [[#C4]]Crownhill PROTON BASIC
to:
!!! [[#C4]]PROTON BASIC
Changed line 252 from:
!!! [[#C5]]microEngineering Labs PicBASIC PRO
to:
!!! [[#C5]]PicBASIC PRO
Changed lines 1-2 from:
The following is the reference sample code used when evaluating different compilers. The code itself is not intended to be optimised in any way. However, each implementation mirrors the Swordfish version as close as is possible with the particular language used.
!!!Swordfish BASIC
to:
The following is the reference sample code used when evaluating different compilers.
*[[#C1 | Swordfish BASIC]]
*[[#C2 | CCS C]]
*[[#C3 | MikroElectronika BASIC]]
*[[#C4 | Crownhill PROTON BASIC]]
*[[#C5 | microEngineering Labs PicBASIC PRO]]
The code itself is not intended to be optimised in any way. However, each implementation mirrors the Swordfish version as close as is possible with the particular language used.
!!! [[#C1]]Swordfish BASIC
*[[#C1 | Swordfish BASIC]]
*[[#C2 | CCS C]]
*[[#C3 | MikroElectronika BASIC]]
*[[#C4 | Crownhill PROTON BASIC]]
*[[#C5 | microEngineering Labs PicBASIC PRO]]
The code itself is not intended to be optimised in any way. However, each implementation mirrors the Swordfish version as close as is possible with the particular language used.
!!! [[#C1]]Swordfish BASIC
Changed line 68 from:
!!!CCS C
to:
!!! [[#C2]]CCS C
Changed line 134 from:
!!!MikroElectronika BASIC
to:
!!! [[#C3]]MikroElectronika BASIC
Changed line 193 from:
!!!Crownhill PROTON BASIC
to:
!!! [[#C4]]Crownhill PROTON BASIC
Changed line 252 from:
!!! microEngineering Labs PicBASIC PRO
to:
!!! [[#C5]]microEngineering Labs PicBASIC PRO
Changed line 2 from:
!!!Swordfish
to:
!!!Swordfish BASIC
Changed line 184 from:
!!!PROTON BASIC
to:
!!!Crownhill PROTON BASIC
Changed lines 242-304 from:
=]
to:
=]
!!! microEngineering Labs PicBASIC PRO
=code [=
Symbol True = 1
Symbol False = 0
Index var Byte
Value var Byte
EncodedValue var Word
DecodedValue var Byte
Success var Bit
TimerValue var word
TMR1L = 0
TMR1H = 0
PIE1.0 = 1
T1CON.0 = 1
Value = 210
GoSub Encode ' pass Value, return in EncodedValue
GoSub Decode ' pass EncodedValue, return DecodedValue
T1CON.0 = 0
' output results...
End
' encode...
Encode:
EncodedValue = 0
For Index = 0 To 7
If Value.0 = 0 Then
EncodedValue.14 = 1
Else
EncodedValue.15 = 1
EndIf
If Index < 7 Then
EncodedValue = EncodedValue >> 2
EndIf
Value = Value >> 1
Next
Return
' decode...
Decode:
Success = True
For Index = 0 To 7
If EncodedValue.1 = 0 And EncodedValue.0 = 1 Then
DecodedValue.7 = 0
Else
If EncodedValue.1 = 1 And EncodedValue.0 = 0 Then
DecodedValue.7 = 1
Else
Success = False
Return
EndIf
endif
EncodedValue = EncodedValue >> 2
If Index < 7 Then
DecodedValue = DecodedValue >> 1
EndIf
Next
Return
=]
!!! microEngineering Labs PicBASIC PRO
=code [=
Symbol True = 1
Symbol False = 0
Index var Byte
Value var Byte
EncodedValue var Word
DecodedValue var Byte
Success var Bit
TimerValue var word
TMR1L = 0
TMR1H = 0
PIE1.0 = 1
T1CON.0 = 1
Value = 210
GoSub Encode ' pass Value, return in EncodedValue
GoSub Decode ' pass EncodedValue, return DecodedValue
T1CON.0 = 0
' output results...
End
' encode...
Encode:
EncodedValue = 0
For Index = 0 To 7
If Value.0 = 0 Then
EncodedValue.14 = 1
Else
EncodedValue.15 = 1
EndIf
If Index < 7 Then
EncodedValue = EncodedValue >> 2
EndIf
Value = Value >> 1
Next
Return
' decode...
Decode:
Success = True
For Index = 0 To 7
If EncodedValue.1 = 0 And EncodedValue.0 = 1 Then
DecodedValue.7 = 0
Else
If EncodedValue.1 = 1 And EncodedValue.0 = 0 Then
DecodedValue.7 = 1
Else
Success = False
Return
EndIf
endif
EncodedValue = EncodedValue >> 2
If Index < 7 Then
DecodedValue = DecodedValue >> 1
EndIf
Next
Return
=]
Changed lines 47-51 from:
to:
dim Timer as TMR1L.AsWord
Timer = 0
PIE1.0 = 1
T1CON.0 = 1
Timer = 0
PIE1.0 = 1
T1CON.0 = 1
Added lines 54-57:
T1CON.0 = 0
// output results...
end
// output results...
end
Deleted lines 58-66:
=code [=
Timer = 0
PIE1.0 = 1
T1CON.0 = 1
Result = Encode(210)
Decode(Result, Value)
T1CON.0 = 0
=]
Added lines 106-110:
#byte PIE1 = 0x0F9D
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
Changed lines 115-116 from:
to:
set_timer1(0);
TMR1IE = 1;
TMR1ON = 1;
Result = Encode(210);
Decode(Result, &Value);
TMR1ON = 0;
// output results...
TMR1IE = 1;
TMR1ON = 1;
Result = Encode(210);
Decode(Result, &Value);
TMR1ON = 0;
// output results...
Changed lines 125-142 from:
=cpp [=
#byte PIE1 = 0x0F9D
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
void main() {
int8 Value;
int16 Result;
set_timer1(0);
TMR1IE = 1;
TMR1ON = 1;
Result = Encode(210);
Decode(Result, &Value);
TMR1ON = 0;
}
to:
!!!MikroElectronika BASIC
=code [=
' Encode...
sub function Encode(dim pValue as byte) as word
dim Index as byte
Result = 0
for index = 0 to 7
if pValue.0 = 0 then
Result.14 = 1
else
Result.15 = 1
end if
if Index < 7 then
Result = Result >> 2
end if
pValue = pValue >> 1
next index
end sub
' Decode
sub function Decode(dim pEncodedValue as word, dim byref pDecodedValue as byte) as boolean
dim Index as byte
dim DecodedValue as byte
Result = true
for Index = 0 to 7
if (pEncodedValue.1 = 0) and (pEncodedValue.0 = 1) then
DecodedValue.7 = 0
else
if (pEncodedValue.1 = 1) and (pEncodedValue.0 = 0) then
DecodedValue.7 = 1
else
Result = false
exit
end if
end if
pEncodedValue = pEncodedValue >> 2
if Index < 7 then
DecodedValue = DecodedValue >> 1
end if
next Index
pDecodedValue = DecodedValue
end sub
main:
dim TMR1 as word absolute 0x0FCE
dim Value as byte
dim Result as word
TMR1 = 0
SetBit(PIE1,0)
SetBit(T1CON,0)
Result = Encode(210)
Decode(Result, Value)
ClearBit(T1CON,0)
' output results...
end.
=code [=
' Encode...
sub function Encode(dim pValue as byte) as word
dim Index as byte
Result = 0
for index = 0 to 7
if pValue.0 = 0 then
Result.14 = 1
else
Result.15 = 1
end if
if Index < 7 then
Result = Result >> 2
end if
pValue = pValue >> 1
next index
end sub
' Decode
sub function Decode(dim pEncodedValue as word, dim byref pDecodedValue as byte) as boolean
dim Index as byte
dim DecodedValue as byte
Result = true
for Index = 0 to 7
if (pEncodedValue.1 = 0) and (pEncodedValue.0 = 1) then
DecodedValue.7 = 0
else
if (pEncodedValue.1 = 1) and (pEncodedValue.0 = 0) then
DecodedValue.7 = 1
else
Result = false
exit
end if
end if
pEncodedValue = pEncodedValue >> 2
if Index < 7 then
DecodedValue = DecodedValue >> 1
end if
next Index
pDecodedValue = DecodedValue
end sub
main:
dim TMR1 as word absolute 0x0FCE
dim Value as byte
dim Result as word
TMR1 = 0
SetBit(PIE1,0)
SetBit(T1CON,0)
Result = Encode(210)
Decode(Result, Value)
ClearBit(T1CON,0)
' output results...
end.
Added lines 184-242:
!!!PROTON BASIC
=code [=
Symbol True = 1
Symbol False = 0
Dim Index As Byte
Dim Value As Byte
Dim EncodedValue As Word
Dim DecodedValue As Byte
Dim Success As Bit
Dim Timer As TMR1L.Word
Timer = 0
PIE1.0 = 1
T1CON.0 = 1
Value = 210
GoSub Encode ' pass Value, return in EncodedValue
GoSub Decode ' pass pEncodedValue, return DecodedValue
T1CON.0 = 0
' output results...
End
' encode...
Encode:
EncodedValue = 0
For Index = 0 To 7
If Value.0 = 0 Then
EncodedValue.14 = 1
Else
EncodedValue.15 = 1
EndIf
If Index < 7 Then
EncodedValue = EncodedValue >> 2
EndIf
Value = Value >> 1
Next
Return
' decode...
Decode:
Success = True
For Index = 0 To 7
If EncodedValue.1 = 0 And EncodedValue.0 = 1 Then
DecodedValue.7 = 0
ElseIf EncodedValue.1 = 1 And EncodedValue.0 = 0 Then
DecodedValue.7 = 1
Else
Success = False
Return
EndIf
EncodedValue = EncodedValue >> 2
If Index < 7 Then
DecodedValue = DecodedValue >> 1
EndIf
Next
Return
=]
=code [=
Symbol True = 1
Symbol False = 0
Dim Index As Byte
Dim Value As Byte
Dim EncodedValue As Word
Dim DecodedValue As Byte
Dim Success As Bit
Dim Timer As TMR1L.Word
Timer = 0
PIE1.0 = 1
T1CON.0 = 1
Value = 210
GoSub Encode ' pass Value, return in EncodedValue
GoSub Decode ' pass pEncodedValue, return DecodedValue
T1CON.0 = 0
' output results...
End
' encode...
Encode:
EncodedValue = 0
For Index = 0 To 7
If Value.0 = 0 Then
EncodedValue.14 = 1
Else
EncodedValue.15 = 1
EndIf
If Index < 7 Then
EncodedValue = EncodedValue >> 2
EndIf
Value = Value >> 1
Next
Return
' decode...
Decode:
Success = True
For Index = 0 To 7
If EncodedValue.1 = 0 And EncodedValue.0 = 1 Then
DecodedValue.7 = 0
ElseIf EncodedValue.1 = 1 And EncodedValue.0 = 0 Then
DecodedValue.7 = 1
Else
Success = False
Return
EndIf
EncodedValue = EncodedValue >> 2
If Index < 7 Then
DecodedValue = DecodedValue >> 1
EndIf
Next
Return
=]
Added lines 117-121:
#byte PIE1 = 0x0F9D
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
Deleted lines 133-141:
=cpp [=
#byte PIE1 = 0x0F9D
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
=]
Added lines 1-137:
The following is the reference sample code used when evaluating different compilers. The code itself is not intended to be optimised in any way. However, each implementation mirrors the Swordfish version as close as is possible with the particular language used.
!!!Swordfish
=code [=
// encode...
function Encode(pValue as byte) as word
dim Index as byte
Result = 0
for index = 0 to 7
if pValue.0 = 0 then
Result.14 = 1
else
Result.15 = 1
endif
if Index < 7 then
Result = Result >> 2
endif
pValue = pValue >> 1
next
end function
// decode...
function Decode(pEncodedValue as word, byref pDecodedValue as byte) as boolean
dim Index as byte
dim DecodedValue as byte
Result = true
for Index = 0 to 7
if pEncodedValue.1 = 0 and pEncodedValue.0 = 1 then
DecodedValue.7 = 0
elseif pEncodedValue.1 = 1 and pEncodedValue.0 = 0 then
DecodedValue.7 = 1
else
Result = false
exit
endif
pEncodedValue = pEncodedValue >> 2
if Index < 7 then
DecodedValue = DecodedValue >> 1
endif
next
pDecodedValue = DecodedValue
end function
dim Value as byte
dim Result as word
Result = Encode(210)
Decode(Result, Value)
=]
For timing measurements, the following was used...
=code [=
Timer = 0
PIE1.0 = 1
T1CON.0 = 1
Result = Encode(210)
Decode(Result, Value)
T1CON.0 = 0
=]
!!!CCS C
=cpp [=
// encode....
int16 Encode(int8 pValue)
{
int8 Index;
int16 Result;
result = 0;
for(Index=0;Index<8;Index++)
{
if (bit_test(pValue,0) == 0)
bit_set(Result,14);
else
bit_set(Result,15);
if (Index < 7)
Result = Result >> 2;
pValue = pValue >> 1;
}
return(Result);
}
// decode...
int1 Decode(int16 pEncodedValue, int8 *pDecodedValue)
{
int8 Index;
int8 DecodedValue;
for(Index=0;Index<8;Index++)
{
if ((bit_test(pEncodedValue,1) == 0) && (bit_test(pEncodedValue,0) == 1))
bit_clear(DecodedValue,7);
else if ((bit_test(pEncodedValue,1) == 1) && (bit_test(pEncodedValue,0) == 0))
bit_set(DecodedValue,7);
else
return(0);
pEncodedValue = pEncodedValue >> 2;
if (Index < 7)
DecodedValue = DecodedValue >> 1;
}
*pDecodedValue = DecodedValue;
return(1);
}
void main() {
int8 Value;
int16 Result;
Result = Encode(210);
Decode(Result, &Value);
}
=]
For timing measurements, the following was used...
=cpp [=
void main() {
int8 Value;
int16 Result;
set_timer1(0);
TMR1IE = 1;
TMR1ON = 1;
Result = Encode(210);
Decode(Result, &Value);
TMR1ON = 0;
}
=]
and where
=cpp [=
#byte PIE1 = 0x0F9D
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
=]
!!!Swordfish
=code [=
// encode...
function Encode(pValue as byte) as word
dim Index as byte
Result = 0
for index = 0 to 7
if pValue.0 = 0 then
Result.14 = 1
else
Result.15 = 1
endif
if Index < 7 then
Result = Result >> 2
endif
pValue = pValue >> 1
next
end function
// decode...
function Decode(pEncodedValue as word, byref pDecodedValue as byte) as boolean
dim Index as byte
dim DecodedValue as byte
Result = true
for Index = 0 to 7
if pEncodedValue.1 = 0 and pEncodedValue.0 = 1 then
DecodedValue.7 = 0
elseif pEncodedValue.1 = 1 and pEncodedValue.0 = 0 then
DecodedValue.7 = 1
else
Result = false
exit
endif
pEncodedValue = pEncodedValue >> 2
if Index < 7 then
DecodedValue = DecodedValue >> 1
endif
next
pDecodedValue = DecodedValue
end function
dim Value as byte
dim Result as word
Result = Encode(210)
Decode(Result, Value)
=]
For timing measurements, the following was used...
=code [=
Timer = 0
PIE1.0 = 1
T1CON.0 = 1
Result = Encode(210)
Decode(Result, Value)
T1CON.0 = 0
=]
!!!CCS C
=cpp [=
// encode....
int16 Encode(int8 pValue)
{
int8 Index;
int16 Result;
result = 0;
for(Index=0;Index<8;Index++)
{
if (bit_test(pValue,0) == 0)
bit_set(Result,14);
else
bit_set(Result,15);
if (Index < 7)
Result = Result >> 2;
pValue = pValue >> 1;
}
return(Result);
}
// decode...
int1 Decode(int16 pEncodedValue, int8 *pDecodedValue)
{
int8 Index;
int8 DecodedValue;
for(Index=0;Index<8;Index++)
{
if ((bit_test(pEncodedValue,1) == 0) && (bit_test(pEncodedValue,0) == 1))
bit_clear(DecodedValue,7);
else if ((bit_test(pEncodedValue,1) == 1) && (bit_test(pEncodedValue,0) == 0))
bit_set(DecodedValue,7);
else
return(0);
pEncodedValue = pEncodedValue >> 2;
if (Index < 7)
DecodedValue = DecodedValue >> 1;
}
*pDecodedValue = DecodedValue;
return(1);
}
void main() {
int8 Value;
int16 Result;
Result = Encode(210);
Decode(Result, &Value);
}
=]
For timing measurements, the following was used...
=cpp [=
void main() {
int8 Value;
int16 Result;
set_timer1(0);
TMR1IE = 1;
TMR1ON = 1;
Result = Encode(210);
Decode(Result, &Value);
TMR1ON = 0;
}
=]
and where
=cpp [=
#byte PIE1 = 0x0F9D
#byte T1CON = 0x0FCD
#bit TMR1IE = PIE1.0
#bit TMR1ON = T1CON.0
=]