Math operation in assembly code

In summary, the conversation is about understanding calculations of binary numbers in the context of the PIC 16f84 microprocessor. It is mentioned that a variable can have a maximum value of 256 and if a larger value is needed, another variable must be used to count the number of overflows. An example is given and a question is asked about how the result is stored in the W register when the value is more than 256. A suggestion is made to use a c compiler for PIC to generate the assembly code for the desired calculation.
  • #1
akueddy
14
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
  • #2
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.
 
  • #3
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.
 

1. What is assembly code?

Assembly code is a low-level programming language that is used to write instructions for a computer's processor. It is a human-readable representation of machine code, which is the language that computers use to execute instructions.

2. How are math operations performed in assembly code?

Math operations in assembly code are performed using a series of instructions that manipulate the data stored in the computer's processor. These instructions vary depending on the specific processor and the type of math operation being performed.

3. What are the benefits of using assembly code for math operations?

Using assembly code for math operations allows for precise control over the computer's processor, resulting in faster and more efficient calculations. It also allows for optimization of code, making it useful for tasks that require high performance.

4. What are some common math operations that can be performed in assembly code?

Some common math operations that can be performed in assembly code include addition, subtraction, multiplication, and division. More complex operations, such as bitwise operations and floating-point calculations, are also possible.

5. How do I learn how to write math operations in assembly code?

To learn how to write math operations in assembly code, it is important to have a solid understanding of the specific processor architecture and instruction set. There are many resources available online, as well as books and courses, that can help you learn assembly code and math operations in more detail.

Similar threads

  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
30
Views
4K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Electrical Engineering
Replies
10
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Programming and Computer Science
Replies
15
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Back
Top