STD: Inconsistency between behaviour and documentation Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
satov
Member
Posts: 15
Joined: Wed Apr 30, 2025 3:34 pm

STD: Inconsistency between behaviour and documentation

Post by satov »

Hello!

I'm using the instruction STD (STDI, actually) to store two registers at once. The architecture manual says:

Mnemonic and operands:

Code: Select all

STDI d,e,b,i
Operation:

Code: Select all

mem[b + i * Bpw * 2] <- d
mem[b + i * Bpw * 2 + Bpw] <- e
From which I understand that, if I do something like

Code: Select all

std r0, r6, r3[0]
the content of r0 goes into r3[0] and the content of r6 goes into r3[4].

The actual behaviour, however, seems to be the opposite, that is: r0 gets into r3[0] and r6 into r3[4]. Please see the programs below.

Code: Select all

#include <platform.h>
#include <stdio.h>
int foo = 5, bar = 6;
int [[aligned(8)]] baz[2];
int main(void)
{
    baz[0] = foo;   // 5
    baz[1] = bar;   // 6
    printf("%d, %d\n", baz[0], baz[1]); // prints "5, 6"

    asm volatile ("std %0, %1, %2[0]" : : "r"(foo), "r"(bar), "r"(baz) : "memory");
    printf("%d, %d\n", baz[0], baz[1]); // prints "6, 5"
 
    return 0;
}
The assembler produces this code, which seems to be inline with the documentation (I removed the printf, for clarity)

Code: Select all

ldw r0, dp[foo]       	// 
stw r0, dp[baz]       	// baz[0] = foo;
ldaw r0, dp[baz]     	// r0 contains the base address of the array
ldw r1, dp[bar]       	// 
stw r1, dp[baz+4]   	// baz[1] = bar;
ldw r1, dp[foo]       	// r1 <= foo
ldw r2, dp[bar]       	// r2 <= bar
#APP
std r1, r2, r0[0]     	// should be r0[0] <= r1, r0[4] <= r2
#NO_APP
Am I misunderstanding something, or the documentation is wrong?
View Solution
Joe
Verified
XCore Addict
Posts: 130
Joined: Sun Dec 13, 2009 1:12 am

Post by Joe »

Hi,

Agree this isn't clear but the default syntax of the assembly language is different to the architecture manual, I believe for readability.

https://www.xmos.com/documentation/XM-0 ... embly.html

"The assembly instructions are summarized below using the default assembly syntax. The XMOS XS1 Architecture documents the architectural syntax of the instructions. The syntax directive is used to switch the syntax mode."

You can switch between the different syntax modes with the following command:

https://www.xmos.com/documentation/XM-0 ... tml#syntax

For the STD command, in the ISA the ordering is D, E. In the default assembly syntax the ordering is E, D.

Cheers,
Joe
XMOS hardware grey beard.
satov
Member
Posts: 15
Joined: Wed Apr 30, 2025 3:34 pm

Post by satov »

Ah! Thanks. I wasn't aware of the two syntaxes.