I am considering inserting some assembly code into a PBP program for the first time. I know the best way to learn is to just do it. Unfortunately, I know that calling assembly code from a higher level language can be tricky and my debugging resources are limited to using the PIC serial port to send select variable values to a terminal program running on my PC. I don't want to spend a lot of time with that method just to learn about basic stuff that probably you guys on the forum know right off.
If someone can review my following example and let me know if it has a chance of success or what's not right with it, I would much appreciate that.
So I have a PBP program to start, with three variables defined. Two variables I want to multiply using the fast, hardware multiplier in the PIC (VarA and VarB). The third variable is the result of the multiplication, (Result). I want to do this because the hardware multiplier is very fast and I have many of these multiplies to do in nested loops. All numbers are unsigned, positive.
VarA var byte
VarB var byte
Result var word
Next I have the assy code which I have done the best I can with, without testing, and without ever programming a PIC in assy language before -- just reading stuff. (Ignore the dots. I put them there just to make it more readable.)
ASM ' (PBP statement)
movf........_VarA, w
mulwf ....._VarB ;mult A and B
movf........PRODL, w
movwf....._Result.BYTE0 ;put low byte in Result
movf........PRODH, w
movwf....._Result.BYTE1 ;put high byte in Result
ENDASM ' (PBP statement)
One thing I can't determine is if I can just insert this ASM code block anywhere in the PBP program and it will execute in sequence like ordinary PBP statements, or do I have to call it like a subroutine when I need it and place the code block at the beginning of the PBP program.
Another question I have is if the .BYTE modifier will work in an ASM block, or do I have to store to separate byte variables and combine them in the PBP program.
Also should that ASM code block work? Is there anything that looks wrong? Thanks.
If someone can review my following example and let me know if it has a chance of success or what's not right with it, I would much appreciate that.
So I have a PBP program to start, with three variables defined. Two variables I want to multiply using the fast, hardware multiplier in the PIC (VarA and VarB). The third variable is the result of the multiplication, (Result). I want to do this because the hardware multiplier is very fast and I have many of these multiplies to do in nested loops. All numbers are unsigned, positive.
VarA var byte
VarB var byte
Result var word
Next I have the assy code which I have done the best I can with, without testing, and without ever programming a PIC in assy language before -- just reading stuff. (Ignore the dots. I put them there just to make it more readable.)
ASM ' (PBP statement)
movf........_VarA, w
mulwf ....._VarB ;mult A and B
movf........PRODL, w
movwf....._Result.BYTE0 ;put low byte in Result
movf........PRODH, w
movwf....._Result.BYTE1 ;put high byte in Result
ENDASM ' (PBP statement)
One thing I can't determine is if I can just insert this ASM code block anywhere in the PBP program and it will execute in sequence like ordinary PBP statements, or do I have to call it like a subroutine when I need it and place the code block at the beginning of the PBP program.
Another question I have is if the .BYTE modifier will work in an ASM block, or do I have to store to separate byte variables and combine them in the PBP program.
Also should that ASM code block work? Is there anything that looks wrong? Thanks.
Comment