12.6 Creating a Decrementing Modulo Buffer in Y Memory

A decrementing modulo buffer for use in assembly language can be easily defined in C. In this case, the ending address +1 of the array must be aligned. There is not a suitable predefined macro in the processor header files for this purpose, so variable attributes are specified directly. The far attribute is recommended because Y memory does not fall within the near space on all devices, and the compiler uses a small-data memory model by default.

#include "stdio.h"

int __attribute__((space(ymemory), far, reverse(128))) ybuf[50];

void main()
{
  printf("Should be zero: %x\n",((int) &ybuf + sizeof(ybuf)) % 128);
}

The equivalent definition in assembly language appears below. Reverse section alignment can only be specified as an argument to the .section directive.

       .global _ybuf
       .section *,ymemory,reverse(128)
_ybuf: .space 100