Include <libs\18c452.bas>
Sub main()
Dim a As uByte, b As uByte, c As uByte
b=150
c=10
a=Divide8Bit(b,c) ' a = b / c
End Sub
' unsigned 8 bit divide taken from lib1.lib to show
' freely mixing assembly and basic commands
Function Divide8Bit(accb As uByte,WREG As uByte) ' using WREG as the last argument will save code space
' and execution time
Dim accd As uByte
Dim accc As uByte
Dim acca As uByte
acca=WREG ' save the second argument
accd=accb: accb=0: accc=0 ' initialize variables
Repeat 8
bcf STATUS,C
rlcf ACCD,F ' bank bits are automaticall set if needed
rlcf ACCC,F
If accc<acca Then
STATUS.0=0
Else
accc=accc-acca
STATUS.0=1
End If
rlcf ACCB,F,0
End Repeat
End Function accb