<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60204>60204</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AVR] clang "error: invalid % escape in inline assembly string" for `%~` and `%!`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sprintersb
</td>
</tr>
</table>
<pre>
avr-gcc supports the following zero-argument % sequences in inline assembly that has arguments:
* `%!` resolves to the letter `e` if the device suports `eicall` and `eijmp`. Otherwise, it resolves to the empty string.
* `%~` resolves to the letter `r` for devices with at most 8KiB of program memory. Otherwise, it resolves to the empty string.
This allows to emit appropriate call and jmp instructions depending on the device:
```c++
int main (void)
{
__asm ("%~call 0" :);
__asm ("%~jmp 0" :);
__asm ("%!icall" :);
__asm ("%!ijmp" :);
}
```
Compiled for ATmega8, the inline asm part will compile to
```
rcall 0
rjmp 0
icall
ijmp
```
whereas on ATmega2560, it will be:
```
call 0
jmp 0
eicall
eijmp
```
A work-around is to have several versions of the code depending on `__AVR_3_BYTE_PC__` and similar.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVM-PszYQ_WvMZZQITCDJgUN2t7n00OrT6pN6QgYmMFv_oLYh2h76t1c2Sb7dbFpVlRBo7OfhzbznEc5RrxErVjyx4iURkx-MrdxoSXu0rkka071XYrarvm3BTeNorHfgB4STkdKcSffwJ1qzErafFGoPjBfg8I8JdYsOSANpSRpBOIeqke_gB-FhEA6uRxzLDyx9Yen1zQ_AypTxgvGMlSlYdEbO6MCb-GuJ3qMNGAzbdIqrHc7UYiAZOYZdaoWUASJ0tyy8qZGV6Rp-8QPaMzlk_BnIf_kFqtG_g_OWdL--p_XXv5OyYftk7IWRgzP5AYQHZZyH3c_0BOYEozW9FQoUKmPf_x-j-H4dyIEIYkQsKvIgxtGa0ZLwCKEHsQFvagTSztup9WS0gw5H1F2Q0OgPLfwhR5kuT8v4U3jiKmkPSpAGxnezoY7x_QW-vSAAAOpaOBUgjPPQssgiZZxDSM_3LL-C75GB5kPg16yMZ4vE_xkd9P8KZtuXu4qX8NmokSR2Uc3Dq8Je7II8oVc3WysYhfVwJimhXQ6ANw_zsXRvL424xUu513Ap5xYFuo8SnQe0KFzQbaHFi-DMaJxIpHmg4i3tHYXPDPAzBfxHDgc4G_v7Slgz6Q4omm8QM4LDGa2QMKN10WdmuaCt6fCz51iZ1vXh-7c6r59-e_2p_vW5rq_X1ZEiKezF6klX5d0-34sEq6zcbvJ9XvAsGapC5F3Od7vitBW82HTlLi-aLCvLpuNlJ9qEKp7yPM04z_Jst8nW2xI3m7JJm2a724tGsE2KSpBcSzmrtbF9Qs5NWJUpTzeJFA1Kdx2QtgqgVTP1jm1SSc67H8c8eRlH6eH7N1a8QCuF7oFxjtYay_IDkJ6FpC7OSHStGPHRgFzueLBpsN2HkXOZYrfBmExWVoP3Y5yg_Mj4sSc_TM26NYrxY2B2-axGa96w9YwfY3WO8WMs8O8AAAD___Okzrw">