12.5 Creating an Incrementing Modulo Buffer in X Memory

An incrementing modulo buffer for use in assembly language can be easily defined in C. In this example, the macro _XBSS is used to define an array whose memory alignment is the smallest power of two that is greater than or equal to its size. _XBSS is defined in the device header file. The generic header file xc.h is used to access this device header file.

#include "xc.h"
#include "stdio.h"

int _XBSS(128) xbuf[50];

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

The equivalent definition in assembly language appears below. The section alignment could have specified with a separate .align directive. By using * as a section name, the linker is afforded maximum flexibility to allocate memory.

       .global _xbuf
       .section *,xmemory,bss,align(128)
_xbuf: .space 100