From 38a24f172f31e66bd11cd98d93f86824e9f3a11f Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 14 Apr 2024 02:34:28 +0630 Subject: Finished todo on importing another file --- todo.org | 78 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/todo.org b/todo.org index b8bda39..2fac332 100644 --- a/todo.org +++ b/todo.org @@ -19,45 +19,6 @@ Like in FASM or NASM where we can give certain helpful instructions to the assembler. I'd use the ~%~ symbol to designate preprocessor directives. -** WIP Import another file -Say I have two "asm" files: /a.asm/ and /b.asm/. - -#+CAPTION: a.asm -#+begin_src asm - global main -main: - push.word 1 - push.word 1 - push.word 1 - sub.word - sub.word - call b-println - halt -#+end_src - -#+CAPTION: b.asm -#+begin_src asm -b-println: - print.word - push.byte '\n' - print.char - ret -#+end_src - -How would one assemble this? We've got two files, with /a.asm/ -depending on /b.asm/ for the symbol ~b-println~. It's obvious they -need to be assembled "together" to make something that could work. A -possible "correct" program would be having the file /b.asm/ completely -included into /a.asm/, such that compiling /a.asm/ would lead to -classical symbol resolution without much hassle. As a feature, this -would be best placed in the preprocessor as symbol resolution occurs -in the third stage of parsing (~process_presults~), whereas the -preprocessor is always the first stage. - -That would be a very simple way of solving the static vs dynamic -linking problem: just include the files you actually need. Even the -standard library would be fine and not require any additional work. -Let's see how this would work. ** TODO Macros Essentially constants expressions which take literal parameters (i.e. tokens) and can use them throughout the body. Something like @@ -243,3 +204,42 @@ memory to use in the stack). 2024-04-09: Found the ~hto_e~ functions under =endian.h= that provide both way host to specific endian conversion of shorts, half words and words. This will make it super simple to just convert. +** DONE Import another file +Say I have two "asm" files: /a.asm/ and /b.asm/. + +#+CAPTION: a.asm +#+begin_src asm + global main +main: + push.word 1 + push.word 1 + push.word 1 + sub.word + sub.word + call b-println + halt +#+end_src + +#+CAPTION: b.asm +#+begin_src asm +b-println: + print.word + push.byte '\n' + print.char + ret +#+end_src + +How would one assemble this? We've got two files, with /a.asm/ +depending on /b.asm/ for the symbol ~b-println~. It's obvious they +need to be assembled "together" to make something that could work. A +possible "correct" program would be having the file /b.asm/ completely +included into /a.asm/, such that compiling /a.asm/ would lead to +classical symbol resolution without much hassle. As a feature, this +would be best placed in the preprocessor as symbol resolution occurs +in the third stage of parsing (~process_presults~), whereas the +preprocessor is always the first stage. + +That would be a very simple way of solving the static vs dynamic +linking problem: just include the files you actually need. Even the +standard library would be fine and not require any additional work. +Let's see how this would work. -- cgit v1.2.3-13-gbd6f