Normal programming question


Closed Thread
Results 1 to 5 of 5
  1. #1
    stevenlkz's Avatar
    stevenlkz Guest

    Default Normal programming question

    I got two questions about the programming of PIC16F877.
    1. Normally, when we rotate 8 time with 8 bit data, we will get back the same data right? But if I rotate one time, then call a subroutine or goto other place, the carry flag already change. Then back to here and rotate again. This loop will go on for 8 time, is it finally still can get back the same data?
    2. If I add 8 bit data with another 8 bit data and the result is is overload to 9 or 10 bit, then how a result will store?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If you are talking about PICBasic, then a rotation will push bits out the end and lose them... they are replaced with zero's being pushed back in...
    Code:
    ' example 1...
    
    a var byte
    
    a=%11111111
    a=a >> 1
    
    ' a now contains %01111111
    
    ' example 2...
    
    a var byte
    
    a=%11111111
    a=a << 3
    
    ' a now contains %11111000
    The result of an addition of two numbers will remain within the variable size you have decalred, and only the bottom eight bits (in a byte) or the bottom 16 bits (in a word) will remain.
    Code:
    ' example 3...
    
    a var byte
    b var byte
    c var byte
    
    b=255
    c=1
    
    a=b+c
    
    ' Result in a = 0 (zero)
    
    ' example 4...
    
    a var word
    b var byte
    c var byte
    
    b=255
    c=1
    
    a=b+c
    
    ' Result in a = 256
    If you need to check for an overflow, then you will need an additional line of code...
    Code:
    ' example 5...
    
    a var byte
    b var byte
    c var byte
    overflow var byte
    
    b=255
    c=1
    
    a=b+c
    if a < b then overflow=1 else overflow=0

  3. #3
    stevenlkz's Avatar
    stevenlkz Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for your help, Melanie. But I am using MPlab compiler.
    I have another 6 question with MPlab assembler programming.
    1. Is the PIC can use to check the value whether it is a positive or negative value?
    2. Is the IF/ELSE statement available in MPlab?
    3. How to compare and get the smallest number between three number?
    4. After I use the fixed point division of the application note, AN617 in microchip, but the output is in floating point, then how to read the result?
    5. If the maximum number of floating point is 0.125 in decimal number, then how many bits should I use for math operation?
    6. In application note, AN575 in microchip, it said that floating point 0X823C5198, but how to read it? What decimal value is it?

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    This is a PICBASIC forum for the MeLabs product, and my answers assumed you were using that compiler. Really for in-depth Assembler, try one of the Microchip forums - eg...

    http://forum.microchip.com/

  5. #5
    stevenlkz's Avatar
    stevenlkz Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, thanks for helping.

Similar Threads

  1. Data Programming Error at 0000
    By cpatnoi in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd May 2009, 03:37
  2. noobie to PICs and PBPro... Programming question.
    By mcphill in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th October 2007, 18:35
  3. 12F675, MPLAB programming question
    By EASY in forum General
    Replies: 0
    Last Post: - 2nd April 2006, 19:28
  4. 12f675 programming question
    By puggy in forum General
    Replies: 3
    Last Post: - 30th November 2004, 23:34
  5. 12f657 programming question
    By puggy in forum General
    Replies: 3
    Last Post: - 8th October 2004, 16:28

Members who have read this thread : 1

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