View Full Version : Accessing MultiByte Variables in Assembler
The Altruist
- 10th September 2009, 15:31
This may have been covered elsewhere, but I'm having trouble figuring out how to access the High and Low Bytes of 16-bit Words in Assembler. I know I can point the FSR register at the _Variable to get the Low byte, add one, and get the High byte, but I was wondering if there was an easier more straightforward way.
Also, I'm using the PM assembler, and I'm wondering if there is an equivalent for banksel?
mehmetOzdemir
- 10th September 2009, 15:54
MYVAR VAR WORD
MYVAR_L VAR MYVAR.lowbyte
MYVAR_H VAR MYVAR.highbyte
ASM
CLRF _MYVAR_L
CLRF _MYVAR_H
ENDASM
YOU CAN USE THIS. I USE THIS METHODE WITH LONG VARIABLES. THERE IS NO PROBLEM.
The Altruist
- 10th September 2009, 16:02
Thank you very much! I'm surprised I didn't think of that.
Now comes the next question.
Is there a "banksel" function equivalent in PM assembler?
mehmetOzdemir
- 10th September 2009, 16:16
Is there a "banksel" function equivalent in PM assembler?
NO THERE ISNT ANY EQUIVALENT FUNCTION.
I KNOW THAT , PIC BASIC PRO MAKES THE BANKSEL FUNCTION ITSELF.
The Altruist
- 10th September 2009, 16:31
I'm trying to use inline Assembler, but I use multiple arrays which means I need to address multiple banks. How can I tell which bank a given array is stored in?
Also, I'm not certain how you mean that banksel is produced by PM itself. I'm using 2.5, and it's choking on errors - all related to my attempts to use banksel.
This may all be simplified if I just specify which bank I want each variable in.
Darrel Taylor
- 10th September 2009, 20:37
I'm having trouble figuring out how to access the High and Low Bytes of 16-bit Words in Assembler.
MyWord VAR WORD BANK0
ASM
movf _MyWord,w ; this gets the LowByte
movwf PORTB
movf _MyWord + 1,w ; this gets the HighByte
movwf PORTC
ENDASM
You can use the CHK?RP macro to locate the bank for any variable.
But if you're accessing arrays, it's probably better to use an FSR/INDF.
<br>
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.