- Are varaibles declared as 8 bit on 8 bit PICs and 16 bit on 16 bit PICs? If so, how does one declare an int or long and do arithmatic with these in assembly on an 8 bit PIC?
Variables are whatever size you want them to be, the logic and arithmetic operations on them are normally done in the size of the registers. In other words, you specify the storage size of the variable in RAM and write whatever code is needed to manipulate it using register sized chunks. Ints and longs do not have any meaning in assembly language but if for example you wanted a 16-bit variable, typically you would assign two adjacent 8-bit bytes to hold it.
- How does one write a function that takes parameters and return a value in assembly? If mean if only use "goto", that is not like calling a function anymore.
You can pass and return values in registers. For parameters bigger than a register you save them in memory, call your function and if necessary return the results in memory. Memory is accessible from anywhere in the program so your function and the remainder of the program can access it at any time. Incidentally, "goto" in PIC language means load the following address value into the program counter, forcing the next instruction to be picked up from that address, it does not take any parameters.
- Does assembly have concept of variable scope e.g variables inside functions cannot be accessed from outside in C?
Scope has nothing to do with the program itself, it is a concept only understood by the assembler so it will vary from one assembler to another. Most people use MPLAB or MPLABX from Microchip, it does allow for local variable names within routines.
- What are steps to add two numbers in assembly together? Does assembly have concept of type i,e signed, unsigned, float, int, short e.t.c?
They do not exist at assemble language level, everything is treated equally. It is up to you how the data is used. To add numbers, typically you would load one into the W register and use the ADDWF instruction to add it to the address the other variable is held. You can save the result in W or the variable address depending on what you set the destination field to. The STATUS bits are updated after a math instruction so you can check for a result of zero and whether a carry was generated. Your code would be responsible for checking the carry bit and if necessary, propagating it through any additional digits in your variable.
- What is the most important thing(s) that a person moving from PIC C to PIC Assembly needs to know before they delve into it?
In my opinion the most important thing is to realize that a C compiler produces assembly language code which is then assembled into your final program. It means anything you can do in C is possible in assembly, you just bypass the high level constructs that C gives you. The big advantage of that is you are no longer weighed down by the 'glue' needed by C to hold the program together so you can write faster and smaller programs. You can still use libraries of functions, in fact you can use the C libraries if you are careful but after some practice you will find you make your own routines and save them for reuse in other programs. Because you have absolute control over the program execution, you can also make exact predictions about timing, you will find this important if you delve into control systems where signal sequences and precise delays are essential.
As Paulfjujo stated, you should make yourself familar with the data sheet for the device you want to use. Although the PIC families have very similar instruction sets, there are of course differences to allow their different peripherals work.
Brian.