Math operation in assembly code

  • Thread starter Thread starter akueddy
  • Start date Start date
  • Tags Tags
    Assembly Code
Click For Summary
SUMMARY

The discussion focuses on performing mathematical operations with binary numbers in assembly code for the PIC16F84 microcontroller. It highlights the need to manage overflow by using multiple variables, specifically counta and countb, to represent values exceeding 256. The example provided illustrates how to calculate the total value and round the result to the nearest integer. Additionally, it suggests using a C compiler to generate assembly code for the desired operations, emphasizing the command 'cc -s myfile.c' to produce the assembly output.

PREREQUISITES
  • Understanding of PIC16F84 microcontroller architecture
  • Familiarity with binary number representation and overflow handling
  • Basic knowledge of assembly language programming
  • Experience with C programming and compiler options
NEXT STEPS
  • Research how to implement overflow handling in PIC16F84 assembly code
  • Learn about the 'incf' and 'btfss' instructions in PIC assembly language
  • Explore the use of C compilers for PIC microcontrollers to generate assembly code
  • Study rounding techniques in assembly language for integer results
USEFUL FOR

Embedded systems developers, assembly language programmers, and anyone working with PIC microcontrollers who needs to perform arithmetic operations efficiently.

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.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 30 ·
2
Replies
30
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 19 ·
Replies
19
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K