Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Math operation in assembly code

  1. Feb 18, 2008 #1
    hi guys,

    Im having trouble trying to understand calculations of binary numbers. In pic16f84 i assume that a variable can have a value of 0 to 256. If i wanted to have a value larger than 256 i need to add another variable and count the number of overflow. for example when counta overflow then countb is increased.

    incf counta
    btfss status,z
    incf countb

    say if countb=2 and counta=2, then the total would be (2*256)+(2)= 514

    My question is what is the assembly code in order to perform the usual maths routine of the combined result provided the end value should just be rounded to the nearest integer?

    example :

    (514/3) - 100 = 71.333 = 71

    How does the result actually stored in the W register when you have a value more than 256?
  2. jcsd
  3. Mar 5, 2008 #2


    User Avatar

    I don't know any thing about PIC 16f84, but I'm familar with MCS-51 microprocessor. So, if you want to get the asm code, there is a simple way.

    use a c compiler for pic , than write the code like: a/3-b;
    then let a = 514 and b =100.
    and see the asm code generated by the compiler.
  4. Mar 5, 2008 #3

    jim mcnamara

    User Avatar
    Science Advisor
    Gold Member

    cc -s myfile.c will produce assembly code in myfile.s for your architecture, if your compiler accepts that -s option. A lot of IDE's provide compiler options, check there.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Math operation in assembly code
  1. Assembly code (Replies: 4)

  2. Assembly laguage (Replies: 5)