While ... Wend


Today 06:42
Forum: Proton Plus Compiler v3
Starter: shantanu@india
Views: 0
Replies: 10
Yesterday 20:20
Forum: Absolute Beginners Section
Starter: moonshadow
Views: 0
Replies: 0
+ Reply to Thread
Results 1 to 7 of 7

Thread: While ... Wend16 days old

  1. #1
    Member SELCUK's Avatar
    Join Date
    Sep 2006
    Posts
    176
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    658.36 MB

    0 Not allowed!

    Default While ... Wend

    Hi,

    WHILE byteVariable < signWordVariable
    'other code here
    WEND

    dont work if comparison variables are different.

    Best Regards,

    Selcuk...
    [url]www.sfy.com.tr[/url]

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,193
    Thumbs Up
    Received: 367
    Given: 132
    Total Downloaded
    1.56 GB

    0 Not allowed!

    Default Re: While ... Wend

    I need a bit more info on the values held in the variables, because comparing signed and unsigned variables usually leads to trouble because they all use 2s complements for signed variables and comparisons but on differing bits sizes, so they are not the same value underneath when below 0, and sometimes not when above 0 and the other is below. That's why I added the casting extensions to the variables. i.e. .VariableType .Byte, .SByte, .Word, .Sword, .Dword, .SDword etc...
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member GAMBOA's Avatar
    Join Date
    Nov 2004
    Posts
    397
    Thumbs Up
    Received: 18
    Given: 0
    Total Downloaded
    184.43 MB

    0 Not allowed!

    Default Re: While ... Wend

    Hi,
    I'm not an expert in programming (or anything).

    But I see implicitly a problem in the expression WHILE byteVariable <signWordVariable. What is done in this expression is to compare two variables. These variables are of a different nature. It's like comparing pears with apples. I believe that the solution would be to adopt another type of analysis.
    Regards,
    Gamboa

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Member SELCUK's Avatar
    Join Date
    Sep 2006
    Posts
    176
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    658.36 MB

    1 Not allowed!

    Default Re: While ... Wend

    Hi Les,

    Thank you for reply.

    Below you can see peice of code that I used in my project using pic18f8722 @ 40 MHz XTAL using PLL. Compiler version is 3.7.1.1
    I use both BYTE and SIGNWORD variables to compare byte array length. Because array length is vary.

    Comparison works from 0 to 127 while length is greater than 127.

    DIM swPointer AS SWORD
    DIM swUzunluk AS SWORD
    DIM bNext AS BYTE
    DIM bChar AS BYTE

    DIM sGelen[512] AS BYTE
    DIM sKomut[24] AS BYTE

    DIM isValidData AS BIT

    ;// other basic code

    IF isValidData = 1 THEN

    ;// Split Commands
    bNext = 0
    swPointer = 0

    WHILE bNext < swUzunluk

    ;PRINT AT 11, 0, "bNext:", DEC bNext

    bChar = sGelen[bNext]
    IF bChar = $0D OR bChar = $7C THEN
    sKomut[swPointer] = $0D

    Works_On_Command()

    swPointer = - 1
    CLEAR sKomut
    ELSE
    sKomut[swPointer] = bChar
    ENDIF
    INC bNext
    INC swPointer

    WEND

    isValidData = 0

    ENDIF


    SUB Works_On_Command()
    ;// Other basic code
    ENDSUB


    ;// other basic code

    Best Regards,

    Selcuk
    [url]www.sfy.com.tr[/url]

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,003
    Thumbs Up
    Received: 186
    Given: 169
    Total Downloaded
    3.99 GB

    0 Not allowed!

    Default Re: While ... Wend

    IIWY I'd copy the byte variable to an sword dummy then do the comparison.
    George.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Member SELCUK's Avatar
    Join Date
    Sep 2006
    Posts
    176
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    658.36 MB

    0 Not allowed!

    Default Re: While ... Wend

    Quote Originally Posted by towlerg View Post
    IIWY I'd copy the byte variable to an sword dummy then do the comparison.
    Hi,

    Yes, You are right. BYTE variable changed with SIGNWORD variable, and my code works.

    Here, I just point it to Les.

    Best Regards,

    Selcuk...
    [url]www.sfy.com.tr[/url]

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,193
    Thumbs Up
    Received: 367
    Given: 132
    Total Downloaded
    1.56 GB

    0 Not allowed!

    Default Re: While ... Wend

    The 0 to 127 tells the issue.

    In a signed byte variable (8-bits) 0 to 127 are positive, while 128 to 255 are negative values -128 to -1. Whenever a signed variable is within an expression or comparison, the compiler automatically performs code for signed variables. However, a signed comparison is looking at the 2s complement, which usually looks at bit-7 of a byte, bit-15 of a word and bit-31 of a dword. If this bit is 1, then the value is negative and the comparison will go no further with looking because it is a positive value against a negative value.

    For example, the code below will never come out of the While loop because the unsigned byte variable is within a signed comparison and it never reaches the value of 128 because it cannot. A signed byte can be 0 to 127, -128 to 0, so it is always less value than what is contained within MySignedWord.

    Dim MySignedWord As SWord
    Dim MyByte As Byte

    MyByte = 127
    MySignedWord = 128

    While MyByte < MySignedWord
    Inc MyByte
    Wend


    Above, the unsigned byte variable MyByte is incremented and as soon as it reaches above 128, it is seen as a negative value to the signed comparison in the While statement, so it can never reach a vale of 128, because 128 onwards is actually -128 and the increment of MyByte then makes it -127, then -126 etc. This is standard with all decent compilers and is why the casting was introduced to the compiler.

    For example:

    Dim MySignedWord As SWord
    Dim MyByte As Byte

    MyByte = 127
    MySignedWord = 128

    While MyByte < MySignedWord.Word
    Inc MyByte
    Wend


    Which makes MySignedWord an unsigned variable only within the comparison so the While loop terminates correctly because the comparison is performed as an unsigned type.

    It is never recommended to compare signed and unsigned variables, and I may introduce some reminders or warnings when the compiler detects them.
    Last edited by Les; 3rd May 2019 at 19:14.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. While ... Wend
    By SELCUK in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 20th January 2018, 12:44
  2. While...Wend clarification
    By joesaliba in forum Proton Plus Compiler v3
    Replies: 7
    Last Post: 24th March 2015, 06:51
  3. WHILE without corresponding WEND ????
    By Puffeltje in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 15th October 2012, 21:10
  4. Parsing Error with While-Wend
    By Mark Rodgers in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 2nd April 2007, 13:23
  5. While Wend
    By Dave-S in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 13th November 2005, 14:30

Members who have read this thread since 9th May 2019, 04:49 : 1

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts