diff options
author | Bill Traynor <wmat@riscv.org> | 2023-08-01 13:15:58 -0400 |
---|---|---|
committer | Bill Traynor <wmat@riscv.org> | 2023-08-01 13:15:58 -0400 |
commit | bebbad41087bbfb713c15db173cc96daf2bd1a81 (patch) | |
tree | 1f3305bac68564041004111f1d34e893e0c9642f /src/example/strlen.s | |
parent | 9cd24d514bc52cb3863b8a547cd1ed40d07727ea (diff) | |
download | riscv-isa-manual-bebbad41087bbfb713c15db173cc96daf2bd1a81.zip riscv-isa-manual-bebbad41087bbfb713c15db173cc96daf2bd1a81.tar.gz riscv-isa-manual-bebbad41087bbfb713c15db173cc96daf2bd1a81.tar.bz2 |
Setting up the inclusion of Vector.
Added Vector and all supporting files.
Diffstat (limited to 'src/example/strlen.s')
-rw-r--r-- | src/example/strlen.s | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/example/strlen.s b/src/example/strlen.s new file mode 100644 index 0000000..1c3af4b --- /dev/null +++ b/src/example/strlen.s @@ -0,0 +1,22 @@ + .text + .balign 4 + .global strlen +# size_t strlen(const char *str) +# a0 holds *str + +strlen: + mv a3, a0 # Save start +loop: + vsetvli a1, x0, e8, m8, ta, ma # Vector of bytes of maximum length + vle8ff.v v8, (a3) # Load bytes + csrr a1, vl # Get bytes read + vmseq.vi v0, v8, 0 # Set v0[i] where v8[i] = 0 + vfirst.m a2, v0 # Find first set bit + add a3, a3, a1 # Bump pointer + bltz a2, loop # Not found? + + add a0, a0, a1 # Sum start + bump + add a3, a3, a2 # Add index + sub a0, a3, a0 # Subtract start address+bump + + ret |