It happened like this;
did a great interview with .I was all substack-jazzed-up from watching that, when I hit some kind of bug.
In my steaming hubris, I declared war.
The creeping concern that I may have fallen into the habit of being totally full of crap, has now goaded me into action.
First Code
make.sh
#!/bin/bash
tcc -c print_string.s && tcc -bt -g print_string.o main.c && ./a.out
print_string.s
.text
.globl print_string
print_string:
pushq %rbp // save previous base pointer
movq %rsp, %rbp // initialize new stack frame
movq %rdi, %r8 // save string address to r8
xorl %edx, %edx // initialize length to 0
leaq (%r8), %rsi // load current string address into rsi
loop_start:
movzbl (%rsi), %eax // load a byte from the string into al
testb %al, %al // check if the byte is zero
jz loop_end // if zero, end of string reached
incq %rsi // increment current string address
incq %rdx // increment length
jmp loop_start // continue looping
loop_end:
movl $1, %edi // load file descriptor (stdout) into edi
movq %r8, %rsi // move original string address back to rsi
movl $0x01, %eax // load syscall number for write into eax
movq %rdx, %rdx // move length to rdx
syscall // invoke syscall
popq %rbp // restore previous base pointer
ret // return from function
main.c
extern void print_string(const char *str);
int main() {
const char *hello = "Hello, World!\n";
const char *pad = "0123456789012345678901234567890123456789\n";
print_string(hello);
print_string(pad);
return 0;
}
Well, imagine my surprise to discover C is recounting itβs string lengths every chance it gets. Now in my old life, we move on from these kinds of things.
But this is bullshit.
So the obvious solution is to write up a new language on my way to competing with Substack as one programmer. lol
June - The start of L0 will target a music player.
A few keys on a typewriter.