<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58876>58876</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[avr] Wrong code for avrtiny core family: wrong encoding of LDS / STS.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sprintersb
</td>
</tr>
</table>
<pre>
Compile the following C code with `--target=avr -Os -mmcu=attiny40`:
```c++
int xx;
int main (void)
{
return xx;
}
```
Disassembling the final ELF will read something like:
```none
0000005c <main>:
5c: 80 91 40 00 lds r24, 0x0040 ; 0x800040 <xx>
60: 90 91 41 00 lds r25, 0x0041 ; 0x800041 <xx+0x1>
64: 08 95 ret
```
which is wrong code because on reduced tiny, `lds` and `sts` are 16-bit instructions. Compiling the same code with avr-gcc and `-mabsdata`, the disassembly reads:
```none
00000046 <main>:
46: 80 a1 lds r24, 0x40 ; 0x800040 <xx>
48: 91 a1 lds r25, 0x41 ; 0x800041 <xx+0x1>
4a: 08 95 ret
```
Notice that not all of SRAM can be accessed by means of `lds`/`sts`, so special care must be taken when using absolute addresses for SRAM.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVF1v6ygQ_TX4ZZQI8EfsBz-0TfvUe6-0XWmfMZCYWwwR4Kb59zs4adrtVuousmwGhjNn5owZvDr1d346GKshjRp23lp_NG4PdyC90nA0aQTS0NUqibDXiZRb8RJg9SvCaprknO2UjDtVFL1IeUPoltCbPF8eSfhtfpZV4xK8vpLygzkJ44Dw9sUbRXh3Ob25eACOoNMc3MdzZLP9FOVsbk0UMeppsDmBJR3jhIX7xwfMw1qEEgqin3Qas4c1z_rfjJ13-rxEl1FLIOVd5knK-6s7QC0Xo2spdAwqCpQCmlZFfAdeEX4H9JVSLAztkDsaLc1mhsvZ3L8hXerWdWck9gmpviKxfyKxCxK_pa_sI151xqMtdDWcR0ZC9b4q23E0cgQT4Rg8VmWRfdBSzFGDd1g0NUutIIucmeC5zKyhIJzKVkxnK2hgzWowCYyLKcwyGe_iGs799SZJFJP-0FrYTKu9lG9Yq0kMUYkkMjsMlk-oq6ynRcH4vWZV87VmVXPVTLD3ynzS7HvFqvaiGPsS56LYf9WrEv9Lr58-GZl_V5HA-QQCO9vv4OmPmx8ghUPtQEipsWQKhhNMWriYHa7CEf5wlS0zjR7iQUuDv4rMKk5zTBkliWft4Djia45ZP9TG2zkhvlIhB4h4YYQl8rrQPWuaTUc3bc0L1ZeqKztRJJOs7kl9i0KTegt_vfdYPoqrua9wAePuxGTsCWtx6UTt0C_HRfKP2ye8Jh7g6c-ndTEH248pHZZOwGT4wx57aR7W0k9oWPvy9lkdgv-tZULTxDjriJO6bTdNMfb1ju8qJXcbyQbFS90wppVslWS8LTvKCysGbWMmTzh3-ggLBM4xkcL0nHLOGG0ZqyrG18NmqAYxKNHVVScUJxXV2IF2nXmsfdgXoV8oDfM-4qY1qMD7Jra42Tu91CrjizmNPvTxEPCa1CEOxRK9X9j_DXELoYU">