Home
Downloads
Licenses Contact

Basic Compiler Debug Test Examples

Maybe it is a good idea to share with you some of the debug test examples used for the compiler engine tests during the software development.
Most of the code tested is functionally meaningless, because the developer's focus was on the inspection of the generated code for accuracy and precision.
Commented lines of code were probably used for the test of compiler error messages...
The newest test examples are on the top of the list.

A tip for advanced and/or curious users:
Be sure to turn on (set to 1 using the Registry Editor) the 'Print Debug Comment Lines in Compiler Listing' registry value for the software package you are using (located in 'HKEY_CURRENT_USER\Software\OshonSoft PIC18 Basic Compiler' registry key, for example), and then inspect the generated assembler listing for these examples, especially for complex expressions related ones at the bottom of the page...



cfor-cnext test
Dim i As Byte
Dim j As Byte
Dim k As Byte

k = 0
CFor (i = 1; i < 7; i++)
        k++
CNext

k = 0
CFor (i = 5, j = 10; i + j < 20; i++, j++)
        k++
CNext



for-next overflow test - long
Dim i As Long
Dim k As Byte

k = 0
For i = 4294967280 To 4294967295 Step 10
        k = k + 1
Next i

For i = 12 To 0 Step -5
        k = k + 1
Next i



for-next overflow test - word
Dim i As Word
Dim k As Byte

k = 0
For i = 65520 To 65535 Step 10
        k = k + 1
Next i

For i = 12 To 0 Step -5
        k = k + 1
Next i



for-next overflow test - byte
Dim i As Byte
Dim k As Byte

k = 0
For i = 240 To 255 Step 10
        k = k + 1
Next i

For i = 12 To 0 Step -5
        k = k + 1
Next i



expressions test #10
Dim x As Word
'Dim oshonsoft_temp15 As Word
Dim x1 As Word
Dim x2 As Word
Dim b1 As Bit
x = x1 && x2
x = x1 || x2
x = !x1
x = x1 % x2
x = --x1
x = ++x1
'b1 = ++x
b1 = x < x1 And x2 != 0
b1 = x < x1 || Not (x2 > 0)
b1 = x < x1 And ~(x2 > 0)
x = x1 << 6
x = x1 ShiftLeft x2
b1 = x < x1 Or x2 > x2 + (x1 >> 3)
'b1 = (x < 1) Mod (x < 0)
'b1 = (x < 1) % (x < 0)
b1 = (x < 1) And !(x < 0)
b1 = (x + 1) > (x + 1)
x1 = x--
x1 = x++
b1 = x < --x1 || Not (x2++ > 0)



expressions test #9 - for-next
Dim i As Byte
Dim j2 As Byte
Dim j As Word
Dim k As Word
Dim k2 As Word
Dim b1 As Bit
Dim s1 As String

j = 1
k = 5
k2 = 0
For i = j + 1 To k * 2 + 1 Step 2
        k2 = k2 + 1
Next i

j2 = 0
For i = 1 To 10 Step 1 + j2
        k2 = k2 + 1
Next i



expressions test #8 - while, csingle, clong
Dim w1 As Word
Dim l1 As Long
Dim s1 As Single
Dim i As Byte
Dim k As Byte
Dim j(5) As Byte

'While 2
'Wend
While 1
        k = k + 1
Wend
'If 2 Then i = 1
If 1 Then i = 2
While i == j(w1)
        k = k + 1
Wend
While s1 - 1 = w1 / 1000
        k = k + 1
Wend
While l1 - 1 = w1 * 1000
        k = k + 1
Wend
While s1 + 1 = CSingle w1 / 1000
        k = k + 1
Wend
While l1 + 1 = CLong w1 * 1000
        k = k + 1
Wend



expressions test #7
Dim w1 As Word
Dim l1 As Long
Dim s1 As Single
Dim i As Byte
Dim j(5) As Byte

5
i
j(5)
j(i)
#i
#j(i)
#i = w1 + 5
i + j = w1 + 5
i + j = w1 + 5 % 1
Sin(s1) = w1 + 5

s1 += w1 / 1000 + 3.14
s1 = w1 / 1000 + 3.14
l1 = w1 * 1000 + 500
If s1 = w1 / 1000 Then i = 0
If l1 = w1 * 1000 Then i = 0
If s1 = CSingle w1 / 1000 Then i = 0
If l1 = CLong w1 * 1000 Then i = 0



expressions test #6 - select case
Dim i As Byte
Dim j As Byte
Select Case i
Case 1
Case 5 + j
Case 2, 3, >= 10 + j
Case Else
EndSelect



expressions test #5 - lcdout
Dim i As Word
Dim a1 As Word
Dim a2 As Word
Dim s1 As String

AllDigital
Lcdinit

s1 = "ab"
a1 = 50
a2 = 50
For i = 0 To 10
        Lcdcmdout LcdClear
        Lcdout s1 + "c", 32, #i, 32, #(i + 1), 32, #-i
        Lcdcmdout LcdLine2Home
        Lcdout #func1(i * 2 + 1), 32, #a1++, 32, #--a2
Next i
a1 = func1(i * 2 + 1 + 2 + 3)
++a1
a2--
a1 == a2
'a1++ +
End

Function func1(arg1 As Word) As Word
func1 = arg1 + 100
End Function



expressions test #4 - logical
Dim b1 As Bit
Dim b2 As Bit
Dim a1 As Word
Dim a2 As Word
Dim x1 As Long
Dim x2 As Long
Dim i As Word
Dim j As Word

a1 += a2 Or x1 && x2
'b1 = !a1
'a1 = b1 ^ b2
'b1 = a1 & b2
'a1 = a1 & b2
b1 = Not b1 || !b1
a1 = a2 | a2 << 2
a1 = a2 ^ ShiftLeft(a2, 2)
b1 = b2 = True
a1 = b1 == b2
b1 = b1 == b2 And a1 <> a2 Or Not a1 != a2

b1 = (i > j * 10 + 5 And i + 10 < j * 20) Or x2 = i * 10000
'a1 = (i > j * 10 + 5 And i + 10 < j * 20) Or x2 = i * 10000
b1 = (i > j * 10 + 5 And i + 10 < j * 20) Or x2 = CLong i * 10000



expressions test #3
Dim a1 As Word
Dim a2 As Word
Dim x1 As Single

a1 += a2
a1 -= Sqr a2
a1 *= x1
a1 /= Log x1



expressions test #2
Dim a1 As Word
Dim a2 As Word
Dim a3 As Word
Dim abs As Single
Dim x1 As Single

a1 = -a2 + "a"
'a1 = -a2 + -100
x1 = -a2 + -100
x1 = -CSingle(a2) + -100
x1 = -abs + -100
abs = -abs
'Const pi = 3.14159265
Const pi = 3.14159
x1 = Sin(-pi - 0.1)
'a1 = a2 * + / a3
'a1 = a2 / a3 a1



new complex expressions evaluation engine test #1
Dim a1 As Word
Dim a2 As Word
Dim a3 As Word
Dim s1 As String
Dim s2 As String
Dim s3 As String
Dim i1 As Byte
Dim i2 As Byte
Dim abs As Single
Dim peaks(10) As Single

a1 = Sqr(a2)
'a1 = #a2
s1 = #a2
s1 = "abcd" + s2
s1 = "abcd" + #a2
s1 = "abcd" + #a2 + s2 + s3
abs = peaks(i1 - 1) - peaks(i1 - 2)
a1 = --a2 / 2
a1 = Sqr ++a2
a1 = --a2 + ++a3
a1 = a2 + a3
a1 = -a2 + +a3
a1 = -a2 + +-a3
a1 = a2-- / 2
a1 = a2-- / 2 + 1 * 2
a1 = a2++
a1 = a2++ + --a2
a1 = a2++ + a2++
a1 = --a2 + a2--
a1 = --a2 + --a2
a1 = a2 = a3 + 1
peaks(i1 - 3) = abs = peaks(i1 - 1) - peaks(i1 - 2)
'a1 = #(a1 + a2 * a3)
s1 = #(a1 + a2 * a3)
a1 + a2 = a2 * a3
a3 = a1 + a2 = a2 * a3



array index check warnings
Dim v1(9) As Word
Dim v2 As Word

v1(-100) = 0
v1(10000) = 0
v1(9) = 10
v1(5) = v1(9) + 5

For v2 = 0 To 9
        v1(v2) = 0
Next v2
For v2 = 9 To 2 Step -1
        v1(v2) = 0
Next v2



array index check warnings (z80, 8085)
'Dim v1a(9) As Integer
'Dim v1b(40000) As Integer
Dim v1(9) As Integer
Dim v2 As Integer

For v2 = 1 To 10
        v1(v2) = 0
Next v2

v1(-100) = 0
v1(10000) = 0
v1(9) = 10
v1(5) = v1(9) + 5

For v2 = 0 To 9
        v1(v2) = 0
Next v2
For v2 = 9 To 2 Step -1
        v1(v2) = 0
Next v2



single precision math calculations test
Dim s1 As Single
s1 = 1.2345 - 0.0666 '1.1679
s1 = 5.0045 * -3.333 '-16.6799985
s1 = 4.444 / 0.234567 '18.945546
s1 = Exp(0.55) '1.7332530
s1 = Sqrt(3.13) '1.7691806
s1 = Log(3.12) '1.1378330
s1 = Exp(3.03) '20.697232
s1 = Sin(2.93) '0.2100172
s1 = Cos(2.83) '-0.9518465
Dim l1 As Long
Dim b1 As Byte
s1 = Exp(3.03) '20.697232
l1 = s1
b1 = s1
While s1 > 15.003
        s1 = s1 - 2
Wend



string test #2
#define STRING_MAX_LENGTH = 18
#define SINGLE_DECIMAL_PLACES = 6
Dim BigNumber1 As String
Dim BigNumber2 As String
Dim result As Single
Dim l_val1 As Long
Dim s_val1 As Single
Dim l_val2 As Long
Dim size As Byte
Dim decpnt As Byte

Const pi = "3.1415938"

BigNumber1 = "4294967295.1234567"
BigNumber2 = "-1.349876"

size = Len(BigNumber1)
decpnt = InStr(BigNumber1, ".")

l_val1 = StrValL(LeftStr(BigNumber1, decpnt - 1))
l_val2 = StrValL(RightStr(BigNumber1, size - decpnt))
result = StrValS(pi)
s_val1 = StrValS(BigNumber2)

Serout PORTB.6, 9600, BigNumber1, " ", #size, " ", #decpnt, 10
Serout PORTB.6, 9600, #l_val1, " ", #l_val2, " ", #s_val1, " ", pi



string test #1
#define SINGLE_DECIMAL_PLACES = 4
Dim str1 As String
Dim str2 As String
Dim lenth As Byte
Dim xyz As Single
Dim array(10) As Byte

str1 = "1234.56789012345"
str2 = "-378.9875"
lenth = Len(str1)
xyz = StrValS(str2)
array(5) = 65

Serout PORTB.6, 9600, str1, 10
Serout PORTB.6, 9600, #lenth, 10
Serout PORTB.6, 9600, #array(4), " ", #array(5), 10

str1(7) = "#"

Serout PORTB.6, 9600, #array(5), " ", #str1(7), Cr
Serout PORTB.6, 9600, str1, Cr
Serout PORTB.6, 9600, #xyz



while type test
Dim s1 As String
Dim s2 As String
Dim b1 As Byte
Dim w1 As Word
Dim l1 As Long
Dim ss1 As Single

b1 = 100
s1 = "aaa"
s2 = "bbb"
s1 = s2 + #b1

While b1 - 10 < 1000
Wend
While b1 - "a" < 100
Wend
While LeftStr(s1, 5) = "aaaaa"
Wend
While b1 = 3
Wend
While b1 + 1 + 1 = b1 * 100
Wend
While "aaa" = "aa"
Wend
While w1 * 10000 < l1 + 10
Wend
While w1 / 1024 > 10.56
Wend
While w1 / 1024 > ss1
Wend



error messages test
Dim b1 As Byte
Dim b2(10) As Byte
Dim i As Byte
Dim s1 As String

i = 10 + s1(10 + i)
'i = 10 + b1(10 + i)
i = 10 + b2(10 + i)
'b1(10 + i) = 10
b2(10 + i) = 10 + b1
s1(10 + i) = f1(10 + b2(1) + b2)
'f1(10 + i) = f1(10 + b2(1) + b2)
End

Function f1(arg1 As Byte) As Byte
f1 = arg1
End Function



complex array index test #2
Dim arr(10) As Byte
Dim arr2(10) As Word
Dim w1 As Word
Dim b1 As Byte

w1 = myfunc1()
w1 = arr(b1)
w1 = arr(b1 + 1)
w1 = arr(b1 + 3) * arr(Sqr(w1 + 1)) + myfunc1 + myfunc2(1)
arr2(b1 + 3) = arr(b1)
'arr2(b1 + Sqr()) = arr(b1 + 1)
arr2(b1 + Sqr(w1 + 1)) = arr(b1 + 1)
arr2(b1 + 3) = arr(b1 + 3) * arr(Sqr(w1 + 1)) + myfunc1 + myfunc2(1)
End

Function myfunc1() As Byte
myfunc1 = 1
End Function

Function myfunc2(arg1 As Byte) As Byte
myfunc2 = 1 + arg1
End Function



complex array index test #1
Dim arr(10) As Byte
Dim w1 As Word
Dim b1 As Byte

'w1 = arr()
w1 = arr(b1)
w1 = arr(b1 + 1)
'w1 = 1 + arr()
'w1 = arr() + 1
'w1 = 1 +
w1 = arr(b1 + 3) * arr(Sqr(w1 + 1))
'w1 = b1 + Sqr()
'w1 = Sqr() + b1
w1 = myfunc1 + myfunc1()
w1 = myfunc1() + myfunc1
'w1 = myfunc2 + myfunc2()
'w1 = myfunc2() + myfunc2
w1 = arr(b1 + 3) * arr(Sqr(w1 + 1)) + myfunc1 + myfunc1()
'w1 = arr(b1 + 3) * arr(Sqr(w1 + 1)) + myfunc1 + myfunc2()
w1 = arr(b1 + 3) * arr(Sqr(w1 + 1)) + myfunc1 + myfunc2(1)
End

Function myfunc1() As Byte
myfunc1 = 1
End Function

Function myfunc2(arg1 As Byte) As Byte
myfunc2 = 1 + arg1
End Function



string as byte array test
Dim y1 As String
Dim i As Byte
y1(5) = "c"
y1(i - 5) = "c"
i = y1(3)
i = y1(i + 1)
y1(i + 2) = y1(i + 3)



complex expressions test
Dim b1 As Byte
Dim b2 As Byte
Dim w1 As Word
Dim w2 As Word
Dim s1 As String
Dim s2 As String

b1 = InStr(s1, b1)
b1 = InStr(s1, Asc(s2))
b1 = InStr(s1, " ")
b2 = InStr(s1, b1 + 3)
b1 = InStr(s1, b1 + 3)
b2 = InStr(s1, w1 + 3)
s1 = InStr(s1, b1)
w2 = InStr(s1, "a") + InStr(s1, "b")

b1 = ((1 + (b1 + 2)) + ((b1 + 3) + 4))
b1 = ((1 + (b2 + 2)) + ((b2 + 3) + 4))
b1 = ((1 + (b1 + 2)) + ((b1 + 300) + 4))
b1 = 100 + (1000000 + b1)
s1 = LeftStr(s2, " ")
s1 = LeftStr(s1, " ")
b1 = 3 + "a"
b1 = b1 * 10
b1 = b1 * 1000
's2 = 3 + "aa"
s1 = #b1 + #b2
s1 = #b1 + "a"
'b1 = LeftStr("aaa", 2)
s1 = "aa" + "bb"
s1 = s1 + "aa"
s1 = "aa" + s1
s1 = s2 + "aa"
s1 = "aa" + s2
s1 = "ABC" + LeftStr(s1, 2)
s1 = LeftStr(s1, 2) + "ABC"
s2 = "ABC" + LeftStr(s1, 2)
s2 = LeftStr(s1, 2) + "ABC"
s1 = LeftStr("aaa" + s1, 5)
s1 = LeftStr(s1 + "aaa", 5)
s1 = LeftStr("aaa" + s2, 5)
s1 = LeftStr(s2 + "aaa", 5)
b1 = Asc("ABC")
b1 = Asc("ABC" + s2)

Lcdinit
Lcdout "aaa", s2, "ABC" + LeftStr(s1, 2), #b1, Asc("ABC")
UART_Init 9600
UART_Write "aaa", s2, "ABC" + LeftStr(s1, 2), #b1, Asc("ABC")



procedure and function arguments test #3
Dim a1 As String
Dim a2 As String

a1 = "abcdefgh"
a2 = f1(f1("a", "c"), f1("b", "d"))
a2 = LeftStr(a1, 4) + f2(f2("k"))
End

Function f2(a1 As String) As String
f2 = a1 + a1
End Function

Function f1(a1 As String, a2 As String) As String
f1 = a1 + a2
End Function



procedure and function arguments test #2
Dim t As Byte
f1 = 100
t = f1
't = Sqr
t = f1 + 1
't = 1 + f1()
t = f1(1)
t = 1 + f1(1)
t = 1 + f1(f1(2))
t = 1 + f1(f1(2) + 1)
t = 1 + f1(1 + f1(2))
t = 1 + f1(f1(f1(5)))
't = f1(1) + f1(1, 1)
t = f1(4) + f1(5)
't = f2(f2(5, 5), f2(10))
t = f2(f2(5, 5), f2(10, 10))
t = f2(f2(6, 6) + 1, f2(11, 11))
t = f2(f2(7, 7), f2(12, 12) + 1)
t = f2(f2(8, 8) + 1, f2(13, 13) + 1)
End

Function f1(a1 As Byte) As Byte
'f1 = 1 + f1(1)
f1 = a1 + 1
f1 = f1 + f1
End Function

Function f2(a1 As Byte, a2 As Byte) As Byte
f2 = a1 + a2
End Function



procedure and function arguments test #1
Gosub sub1
Call p1(f1(10))
Call p1(f1(10) + 1)

Dim x1(5) As Byte
x1(4) = 20
Call p1(x1(4))
Call p1(x1(4) + 1)

Dim t1 As Word
Dim t As Byte

t1 = 10 * 2 + 10 + 100 * 10 + 10 * 2
t = 10 + 20
t = 10 * 2 + 10 + 100 * 10 + 10 * 2
t = 10 * 2 + 10 + 100 * 10 + 10 * 2000
t = 1 + (2 + (3 + (4 + f1(5))))
t = 1 + f1(1)
t = 1 + f1(f1(1))
t = 1 + f1(f1(f1(1)))
t = 1 + f1(t)
t = 1 + f1(x1(4))
t = 1 + f1(x1(4) + 1)
End

sub1:
Return

Proc p1(a1 As Byte)
End Proc

Function f1(a1 As Byte) As Byte
f1 = a1 + 1
End Function



user function calls test #2
Dim y1 As String
Dim y2 As String
y1 = "abcd"
y2 = f2("bcde")
y2 = f2(y1)
y2 = f2("c" + y1)
y2 = f2("c" + f2(y1))
y2 = f2("c" + f2(f2(y1)))

Dim i As Byte
i = 1
y2 = LeftStr(y1, i * 2 + 1)
y2 = LeftStr(y2, i * 2 + 1)
End

Function f2(a2 As String) As String
f2 = LeftStr(a2, 1)
End Function



user function calls test #1
Dim t As Byte
Dim x1 As Byte
Dim x2(5) As Byte

t = f1(1)
t = f1(x1)
t = f1(x2(2))
End

Function f1(a1 As Byte) As Byte
f1 = a1 + 1
End Function