Math operation in assembly code

  • Thread starter Thread starter akueddy
  • Start date Start date
  • Tags Tags
    Assembly Code
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 7K views
akueddy
Messages
14
Reaction score
0
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?
 
Physics news on Phys.org
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.
 
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.