summaryrefslogtreecommitdiff
path: root/rt
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-08-11 19:53:38 -0400
committerOri Bernstein <ori@eigenstate.org>2014-08-11 19:53:38 -0400
commit11ff08b7c5d3d682628b27e0a37b9d7e4deb28b7 (patch)
tree1d82cd27ac8266ae26fbcc719729a0cd0df6e785 /rt
parent1cf88db2a534c237b99a86603d2ecca8c1d37756 (diff)
downloadmc-11ff08b7c5d3d682628b27e0a37b9d7e4deb28b7.tar.gz
Add missing file.
Diffstat (limited to 'rt')
-rw-r--r--rt/common.s57
1 files changed, 57 insertions, 0 deletions
diff --git a/rt/common.s b/rt/common.s
new file mode 100644
index 0000000..7eb2aeb
--- /dev/null
+++ b/rt/common.s
@@ -0,0 +1,57 @@
+.text
+/*
+ * counts the length of the string pointed to
+ * by %r8, returning len in %r9. Does not modify
+ * any registers outside of %r9
+ */
+cstrlen:
+ xorq %r9,%r9
+ jmp .lentest
+
+ .lenloop:
+ incq %r9
+ .lentest:
+ cmpb $0,(%r8,%r9)
+ jne .lenloop
+ ret
+
+
+/*
+ * Counts the size of the null terminated string vector
+ * pointed to by %rbx. Clobbers %r10,%r11
+ */
+count:
+ xorq %r9,%r9
+ movq %rbx,%r11
+.countloop:
+ movq (%r11),%r10
+ testq %r10,%r10
+ jz .countdone
+ addq $1,%r9
+ addq $8,%r11
+ jmp .countloop
+.countdone:
+ ret
+
+/*
+ * iterate over the strings for argc, and put
+ * them into the args array.
+ *
+ * argc in %rax, argv in %rbx, dest vector in %rcx
+ */
+cvt:
+ jmp .cvttest
+.cvtloop:
+ subq $1,%rax
+ movq (%rbx),%r8
+ call cstrlen
+ movq %r8, (%rcx)
+ movq %r9, 8(%rcx)
+ addq $8, %rbx
+ addq $16, %rcx
+.cvttest:
+ testq %rax,%rax
+ jnz .cvtloop
+.cvtdone:
+ ret
+