NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 17 Jan 2013 04:03 PM |
@popin:
Ok, here's one that takes a pointer to the first character, cleans up the stack, and returns the pointer to the end of the string :
0^<0^9?P1+08-8-gd!
Decoded: stack = [ptr]
0^< - Copy the top element and dereference it: stack = [ptr, *ptr] 0^ - copy the value read: stack = [ptr, *ptr, *ptr] 9? - if zero, branch to the end: stack = [ptr, *ptr] P - print: stack = [ptr] 1+ - increment pointer stack = [ptr+1] 08-8-g - Jump back to line 1
d! - pop the null of the stack, leaving the pointer to the end of the string
stack = [ptr+len(string)]
> Yours relies on the string starting at 0
Replace the first 0 in my previous answer with N, and you're there.
> and uses errors to terminate effectively.
No, it uses null-terminated strings - in HackVM, uninitialiazed memory is set to 0 |
|
|
| Report Abuse |
|
|
| 17 Jan 2013 04:34 PM |
| You're still not returning from the subroutine... >.> |
|
|
| Report Abuse |
|