Math operation in assembly code

  • Thread starter Thread starter akueddy
  • Start date Start date
  • Tags Tags
    Assembly Code
AI Thread Summary
Calculating binary numbers in assembly code for the PIC16F84 involves managing variable overflow since the maximum value for a single variable is 256. To handle values larger than 256, an additional variable is needed to track overflow, as demonstrated with counta and countb. The example illustrates how to combine these values to achieve a total, which can then be manipulated mathematically. For converting high-level operations into assembly code, using a C compiler for PIC can simplify the process by generating the necessary assembly instructions. This approach allows for efficient coding without deep knowledge of assembly language specifics.
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?
 
Technology 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
9
Views
2K
Replies
30
Views
6K
Replies
3
Views
2K
Replies
19
Views
5K
Replies
4
Views
5K
Replies
15
Views
2K
Replies
7
Views
3K
Back
Top