ASM and a LDIVU example

Archived XCore tutorials.
User avatar
lilltroll
XCore Expert
Posts: 951
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna
Contact:

ASM and a LDIVU example

Postby lilltroll » Fri May 07, 2010 12:23 pm

If you read the ASM manual ver. 9.9 you will probably get confused - until it's updated.

Reading the The XMOS XS1 Architecture describes the LDIVU operation as

Code: Select all

LDIVU d, e, x, y, v


The XS1 Assembly Language Manual seems to show two incorrect ways of writing it

Code: Select all

LDIVU  d,x,y,e,v    ldivu  d, e, v, x, y


For the moments it's seems to be several errors explaining the operands in the ASM manual.
The correct notation is found in the XS1 architecture.

Code: Select all

#include <stdio.h>

int main(){
   unsigned int Xh=0,Xl=31;
   unsigned int y=5;
   unsigned int Q;
   unsigned int R;
   
   asm("LDIVU %0,%1,%2,%3,%4" : "=r"(Q) , "=r"(R) : "r"(Xh) , "r"(Xl) ,"r"(y));
   printf("Q=%u, R=%u",Q,R);
}


Gives the following result on the console:
Q=6, R=1

31/5 = 6 + 1/5
Q is the Quotent, R is the reminder and the operation is (uint_64) X/(uint_32) y where X is expressed as 2 32-bits number Xhigh and Xlow.

Thus its:
LDIVU Quotent,Reminder,Xhigh,Xlow,Y
Probably not the most confused programmer anymore on the XCORE forum.
User avatar
larry
Respected Member
Posts: 273
Joined: Fri Mar 12, 2010 6:03 pm

Postby larry » Fri May 07, 2010 3:43 pm

Thanks for pointing this out

The architecture manual is indeed correct and doesn't match the result you currently get in assembly as per your experiment. However, that will change in the next tools release - the LDIVU syntax will only be allowed in so called architectural mode, which exactly matches the architecture manual.

For example, in the next tools release (10.4), your experiment would become (note the different order of arguments):

Code: Select all

asm(".syntax architectural\nLDIVU %0,%1,%2,%3,%4\n.syntax default" : "=r"(Q) , "=r"(R) : "r"(Xl) , "r"(y) ,"r"(Xh));


This is a part of a set of changes (hopefully last one) to the various forms of assembler syntax. The assembly language manual is undergoing major changes and will be merged into the Tools User Guide included in the next tools release.

We want to allow 3 different forms of syntax:

  • Standard - ldivu
  • Machine specific - LDIVU_l5r (currently undocumented)
  • Architectural mode in-line with architecture manual - LDIVU (with .syntax directive)

This will be detailed in the 10.4 Tools User Guide.

Who is online

Users browsing this forum: No registered users and 1 guest