Author Topic: MPLab Directives for Multibyte Integers [SOLVED]  (Read 573 times)

0 Members and 1 Guest are viewing this topic.

Offline jpanhaltTopic starter

  • Super Contributor
  • ***
  • Posts: 3479
  • Country: us
MPLab Directives for Multibyte Integers [SOLVED]
« on: January 31, 2024, 11:26:36 am »
When writing Microchip PIC Assembly, I often use the "high" and "low" preprocessor directives to facilitate entering integers, for example  in decimal radix:
Code: [Select]
movlw     high(1234)

MPLab 8.92  accepts: low, high, and upper for three-byte integers.  I suspect there are no such operators for 4-bytes and more.  However, is there a convention for naming the bytes of 4-byte numbers, for example something like low, high, upper, and ****?

Regards, John
« Last Edit: January 31, 2024, 02:22:08 pm by jpanhalt »
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12862
Re: MPLab Directives for Multibyte Integers
« Reply #1 on: January 31, 2024, 01:47:12 pm »
I don't remember seeing one.  MPASM is only for 8 bit PICs, and it seems that at least in the application notes, 32 bit integers are rare except as the result of a 16bx16b multiply, and generally handled as a pair of 16 bit values with explicitly declared addresses for each byte.

If you need that functionality, try:
Code: [Select]
#define top(NN) ((NN)>>.24)Then you can do stuff like:
Code: [Select]
          movlw top(0xDEADBEEF)
Unfortunately you cant emulate the prefix operator style of upper, high and low, but as they don't mind you bracketing their expression, you can use function like syntax with them to match your #defined top().

N.B. The MPASM expression evaluator only uses 32 bit unsigned maths internally so you need to be very careful about order of operations to avoid overflow when using MPASM to evaluate the top byte of 32 bit expressions during the build.
 
The following users thanked this post: jpanhalt

Offline jpanhaltTopic starter

  • Super Contributor
  • ***
  • Posts: 3479
  • Country: us
Re: MPLab Directives for Multibyte Integers [SOLVED]
« Reply #2 on: January 31, 2024, 02:21:32 pm »
Thanks, Ian.

I suspected that was the answer.  Fortunately, my current project only requires 24-bit.  However, I have wondered about whether the top byte in a 32-bit integer had a common name.  I usually just number the bytes 0...3 when using more than 3.  That comes into play when doing fixed point division and similar manipulations. 

It's related to my longer term project for reading a Mitutoyo linear scale encoder and using those readings to control my lathe.  The values for that will be considerably less than 10" in practice, but I am writing code to handle a range of 0 mm to <999.99 mm and the inch equivalents.   Specifically today, I am working on setting up "presets" for machining and needed to convert a preset entered in inches (e.g., 30.1235" to 765.1369mm rounded to 765.14mm).   Of course, anything less than 0.01 mm will be rounded.
« Last Edit: January 31, 2024, 02:23:24 pm by jpanhalt »
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5912
  • Country: es
Re: MPLab Directives for Multibyte Integers [SOLVED]
« Reply #3 on: January 31, 2024, 03:58:43 pm »
However, is there a convention for naming the bytes of 4-byte numbers, for example something like low, high, upper, and ****?

Just Google "mplab asm upper high low" : https://ww1.microchip.com/downloads/en/DeviceDoc/33014L.pdf

6.4 LOW, HIGH AND UPPER OPERATORS.

So I guess there isn't.

Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline jpanhaltTopic starter

  • Super Contributor
  • ***
  • Posts: 3479
  • Country: us
Re: MPLab Directives for Multibyte Integers [SOLVED]
« Reply #4 on: January 31, 2024, 04:32:15 pm »
Hi David,

That's the exact version of the MPLab manual I use.  There is a little more history to it.  Back in 2016, I was playing with the AMS AS3935 lightning detector (aka "Franklin" detector) and noticed in the register map the apparently strange names for 3 registers: L, M, MM in that order (attachment).  I sent a message to AMS,  and the reply was: least (LSB), middle (MSB), and most (MMSB).  I was thinking MM might be "most most" considering the authors probably were fluent in German. ;)  That prompted me to read that section of the MPLab manual to get the correct Microchip names.

John
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf