Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

And or not etc in Oshonsoft

Status
Not open for further replies.
Oshonsoft can use only bitwise operators of C.
eg. & -> And, | -> Or, ~ -> Not, etc.
but no != , ||, && operators
I found that Oshonsoft can use several logical OR + AND operators in IF and WHILE statements. It is mentioned in the manual.

For example the C statement:
if ( a != 1 || b != 2 || c != 3 )
x=0;

will be in Oshonsoft:
If a<>1 Or b<>2 Or c<>3 Then
x=0
 
I found that Oshonsoft can use several logical OR + AND operators in IF and WHILE statements. It is mentioned in the manual.

For example the C statement:
if ( a != 1 || b != 2 || c != 3 )
x=0;

will be in Oshonsoft:
If a<>1 Or b<>2 Or c<>3 Then
x=0
Hi j,
Have you tried your suggestion?
I tried it and it won't compile.
When you state that it is mentioned in the manual, do you mean the example showing 1xOR? Oshonsoft doesn't allow more than 1x OR. Correct me if I'm wrong.
C.
 
From the manual:
In the test expressions of IF-THEN and WHILE statements it is possible to use multiple ORed and multiple ANDed conditions. Six standard comparison operators are available: =, <>, >, >=, <, <=. Multiple comma separated conditions can be used with CASE statements, also.

Yes I tried it succesfully.

Show the code that did not compile.
Did the compiler give a syntax error?
Did you have Endif as the last statement?
 
One thing is, that for some unknown reason, variable name c is a reserved word. Try some other name.
 
One thing is, that for some unknown reason, variable name c is a reserved word. Try some other name.
Vlad uses these Characters within the compiler
Dim C
Dim Z
Dim D
Dim F
Dim N
Dim P
Dim R
Dim S
Dim W
Dim Z
 
One thing is, that for some unknown reason, variable name c is a reserved word. Try some other name.
Hi J,
I had to change all of the variables.
I presume that the [;] is not supposed to be there after the x = 0

Are you getting the answer = 3 with your example?

Hi Eric,
I went through the keyboard looking for ok letters, and used aa ba ca.
c.
 
Hi,
While learning about OPERATORS, I received this from another thread by KEEPITSIMPLESTUPID. I particularly asked it to be in Binary, for my ease of reading.
I now need to study it and understand it better.
It may be better if it was edited down a bit.
C
 

Attachments

  • BIN OR AND NOT MASK.txt
    1.2 KB · Views: 385
";" belongs to C language example.
Do you mean by answer the value of x?
It should be the value of x before the If statement if the three variables are 1, 2 and 3.
0 if it is not initialised or the three variables are not 1, 2 and 3
 
";" belongs to C language example.
Do you mean by answer the value of x?
It should be the value of x before the If statement if the three variables are 1, 2 and 3.
0 if it is not initialised or the three variables are not 1, 2 and 3
Hi J,
Regarding the [;] I get mixed up sometimes.

I tried ORing 1 OR 2 OR 3 on a calculator and got the answer 3, is this what you get with your example?

Where are the examples [Six standard comparison operators are available: =, <>, >, >=, <, <=] shown please?
EDIT: I'm using Oshonsoft.
C.
 
Last edited:
Hi,
Here's Eric's earlier suggestion which does give the answer 3 as the calculator.
C
 

Attachments

  • OR.txt
    752 bytes · Views: 352
You did bitwise OR in the calculator and the result is 3 ( %00000011 in binary )

In the example the value of x is determined by logical OR.
If the the values are 1, 2, 3 then x is unchanged, otherwise 0
 
You did bitwise OR in the calculator and the result is 3 ( %00000011 in binary )

In the example the value of x is determined by logical OR.
If the the values are 1, 2, 3 then x is unchanged, otherwise 0
Hi J,
I think we are at cross purposes, and yes it is Bitwise. I've only just learnt the word.
I think next is for me to look at the TXT on #27 and try to understand it better, then it needs converting to Oshonsoft, which can be a pain sometimes.
Cheers, C.
 
Here are several examples:
DIM A AS BYTE
loop:
SELECT CASE A
CASE 255
A = 1
CASE <= 127
A = A + 1
CASE ELSE
A = 255
ENDSELECT
GOTO loop

DIM A AS BYTE
TRISB = 0
A = 255
WHILE A > 0
PORTB = A
A = A - 1
WAITMS 100
WEND
 
Hi J,
I think we are at cross purposes, and yes it is Bitwise. I've only just learnt the word.
I think next is for me to look at the TXT on #27 and try to understand it better, then it needs converting to Oshonsoft, which can be a pain sometimes.
Cheers, C.
If you are translating this:
if I am correct (after quick check of the source ), you need only bitwise & ( masking bits ) which is And in Oshonsoft.
Other logical stuff can be handled by If then Else statements and with Or / And
 
Last edited:
Hi Eric,
For now, I'm trying your earlier suggestion that I posted in #30 what you post below is a bit advanced for me at the moment, but thanks.
C

If you are translating this:
if I am correct (after quick check of the source ), you need only bitwise & ( masking bits ) which is And in Oshonsoft.
Other logical stuff can be handled by If then Else statements and with Or / And
Hi J,
In this particular case I am not translating the program of your link, but
Here are several examples:
DIM A AS BYTE
loop:
SELECT CASE A
CASE 255
A = 1
CASE <= 127
A = A + 1
CASE ELSE
A = 255
ENDSELECT
GOTO loop

DIM A AS BYTE
TRISB = 0
A = 255
WHILE A > 0
PORTB = A
A = A - 1
WAITMS 100
WEND
 
If you are translating this:
if I am correct (after quick check of the source ), you need only bitwise & ( masking bits ) which is And in Oshonsoft.
Other logical stuff can be handled by If then Else statements and with Or / And
Hi J,
I'm not looking at the program you posted, but some sections of programs, I'm trying to form in Oshonsoft BASIC.
C.
 
Hi,
I'm testing lines of code with firstly ORs. I'm using windows10 calculator then I will try programming Oshonsoft to check the answer.

e,g, To set a byte, perhaps 4x 'OR'ed lines are used. byte = a OR b OR c OR d. e,g, 10000000, 00100000,00001100,00000010

I notice that when the calculator is set to BYTE when bit 7 is 1 then the DECIMAL shows -1. If I set it to WORD, then it shows 255. I'm sure it's something to do with one and twos compliment, but i'm not sure how it affects the result.

In Oshonsoft, this seems to work.
byte = a OR b
byte = byte OR c
byte = byte OR d

How could -1 affect the result, if -1 is what happens, when dealing with only bytes?
EDIT: It appears that the Windows10 calculator only deals with 2s compliment, so hopefully won't affect my results, if I just ignore the -sign.
C.
 
Last edited:
In Oshonsoft, this seems to work. byte = a OR b byte = byte OR c byte = byte OR d
Morning C,
Your above coding does not work in OSH
It dos-not like the 'Byte' or the Reserved A, C or D.

IMHO you are over thinking this problem.
By using a calculator it is not giving you an insight into the simple operations of OR and AND.

Some people learn and retain information easier when they pencil and paper out the maths, try it.

My advice would be to set aside electronic calculators and work out simple pencil and paper examples of ORing , ANDing , of say just two unsigned Bytes.
eg:
try OR on these two 8 Bit Bytes
00000001
00001001
try AND on these two 8 Bit Bytes
00000001
00001001

E
 
Morning Eric,
After being kept in detention aged 7 for not carrying units to 10s in 10s and units, I've had to resort to all sorts of double checking.

Anyway, I have a sheet of binary examples, sheets of paper, a calculator and Oshonsoft SIM.

Here is my first [OR] result:
C.

Morning C,
Your above coding does not work in OSH
It dos-not like the 'Byte' or the Reserved A, C or D.

IMHO you are over thinking this problem.
By using a calculator it is not giving you an insight into the simple operations of OR and AND.

Some people learn and retain information easier when they pencil and paper out the maths, try it.

My advice would be to set aside electronic calculators and work out simple pencil and paper examples of ORing , ANDing , of say just two unsigned Bytes.
eg:
try OR on these two 8 Bit Bytes
00000001
00001001
try AND on these two 8 Bit Bytes
00000001
00001001

E
 

Attachments

  • OR.png
    OR.png
    55.9 KB · Views: 370
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top