diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-05-07 04:17:58 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-05-07 04:17:58 -0700 |
| commit | 24a3e78b55e84951257ee021447490b55dc797b8 (patch) | |
| tree | 24461fe572d57185ad586c655e37ce6a7a008daa | |
| parent | 8541e1f9672fcceca5948b3087e1b871f7d7b109 (diff) | |
make-hello.e works now
wow did labels turn out to be handy Force-Push: yes Change-Id: Iba8d57aed2e5baab5df44b94cdc1d57891b846a9
| -rw-r--r-- | make-hello.e | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/make-hello.e b/make-hello.e index bf0b076..57a08dc 100644 --- a/make-hello.e +++ b/make-hello.e @@ -118,10 +118,12 @@ init-labels 1 pack32 ~ ELF format version ~ Compute the entry pointer. - origin 0x78 + pack64 ~ entry point + ~ origin 0x78 + pack64 ~ entry point + L' start use-label origin + pack64 ~ This includes the origin, intentionally. - 0 pack64 ~ program header offset + L' program-header use-label pack64 + ~ 0 pack64 ~ program header offset ~ We place the program header immediately after the ELF header. This ~ offset is from the start of the file. 0 pack64 ~ section header offset @@ -142,6 +144,7 @@ init-labels ~ ~~ exactly one, and it's always right after the ELF file header. ~ ~~ : elf-program-header + current-offset L' program-header set-label 1 pack32 ~ "loadable" segment type 0x05 pack32 ~ read+execute permission 0 pack64 ~ offset in file @@ -157,10 +160,22 @@ init-labels ; : output-start-routine + current-offset L' start set-label 1 :rax mov-reg64-imm32 - 1 :rdi mov-reg64-imm32 + 1 :rdi mov-reg64-imm64 + origin L' greeting use-label + :rsi mov-reg64-imm64 + L' greeting-size use-label :rdx mov-reg64-imm64 + syscall + 60 :rax mov-reg64-imm32 + 0 :rdi mov-reg64-imm32 + syscall ; +: output-greeting + current-offset dup L' greeting set-label 3unroll + s" Hello, Irenes!" packstring + current-offset 4 roll - L' greeting-size set-label ; + ~ (output memory start, current output point ~ -- output memory start, current output point) ~ @@ -170,6 +185,8 @@ init-labels elf-file-header elf-program-header output-start-routine + output-greeting + current-offset L' total-size set-label ; 0x1000 allocate dup @@ -177,6 +194,11 @@ init-labels all-contents +~ The two-pass magick: Reset the output offset to the beginning of the block. +drop dup + +all-contents + ~ output memory start, current output point over - swap sys-write bye |