title: How can I fix the length of a string in printf when called from RISC-V assembly?
body: <p>I want to get some output on a RISC-V program (assembly) running on top of pk on Spike using newlib.</p>
  <p>I can call printf with null terminated strings eg (snippet)</p>
  <pre><code>la a0 msg_
  jal printf
  
  .data
  msg_ .ascii &quot;MESSAGE IS \n&quot;
  .equ len_msg_, . - msg_
  </code></pre>
  <p>Will print out MESSAGE IS - but how do I pass the length of the string to the call? I have tried a1 - a7 and it doesn't <em>seem</em> to be them and nor can I get putting the length I want on the stack to work (I might just be doing this wrong but in any case more or less the first thing the printf function seems to do is save lots of registers on the stack so I don't think that would work).</p>
  <p>To add to my puzzlement, I have used Compiler Explorer (<a href="https://godbolt.org/z/vscGPG" rel="nofollow noreferrer">https://godbolt.org/z/vscGPG</a>) and I can see no sign that anything for the length is being passed. What have I missed?</p>