From e3ccf5d976965dbda58db4f7d7ec663ce0b0fdf9 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 9 Nov 2021 20:00:56 -0500 Subject: offsets for label definitions, immediates --- 01/README.md | 9 +- 02/in01 | 20214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 02/in02 | 4 +- 3 files changed, 20194 insertions(+), 33 deletions(-) diff --git a/01/README.md b/01/README.md index 1fc5f8c..888454a 100644 --- a/01/README.md +++ b/01/README.md @@ -319,19 +319,18 @@ very end: 00 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 -00 00 03 00 00 00 00 00 -00 00 03 00 00 00 00 00 +00 00 08 00 00 00 00 00 +00 00 08 00 00 00 00 00 00 10 00 00 00 00 00 00 -This is at the position for `||`, and it contains the ELF header. One thing you +This is at the position for `||`, and it contains an ELF header. One thing you might notice is that we decided that each entry is 8 bytes long, but this one is 0x79 = 121 bytes long! It's okay, our code doesn't actually check that we're using less than 8 bytes of data, but it means that the entries for certain commands, e.g. `}\n` will land right in the middle of the data for the ELF header. But by a lucky coincidence, all those entries actually land on 0 bytes, -so they'll just be treated as unrecognized (as they should be). So it's all -good. +so they'll just be treated as unrecognized (as they should be). ## limitations diff --git a/02/in01 b/02/in01 index 721ff02..5ae547b 100644 --- a/02/in01 +++ b/02/in01 @@ -1,5 +1,5 @@ || ELF Header -;jm;cd;cd;cd;cd jump to start of first pass +;jm;73;00;00;00 jump to start of first pass ;'i;'n;'0;'2;00 (0x40007d) input filename ;'o;'u;'t;'0;'2;00 (0x400082) output filename ;00;00;' ;'n;'o;'t;' ;'r;'e;'c;'o;'g;'n;'i;'z;'e;'d;\n;00;00;00;00;00;00 (0x400088) error message/where we read to @@ -12,7 +12,7 @@ unused padding ;00;00;00;00;00;00;00;00;00;00;00;00;00;00;00;00 ;00;00;00;00;00;00;00;00;00;00;00;00;00;00;00;00 --- code starts here +-- code starts here (0x4000f0) ;im;7d;00;40;00;00;00;00;00 pointer to input filename ;JA @@ -42,7 +42,7 @@ the segment we're loading in includes the ELF header at address 0x400000, so we ;im;01;00;00;00;00;00;00;00 write ;sy --- read command -- +-- read command (0x400174) -- ;im;03;00;00;00;00;00;00;00 input file descriptor ;JA ;im;88;00;40;00;00;00;00;00 where to read to @@ -74,7 +74,7 @@ look at second byte of command ;BA rbx now contains the command offset ;im;d0;e9;00;00;00;00;00;00 ':' << 10 | ':' << 3 -;cm;jn;cd;cd;cd;cd +;cm;jn;19;01;00;00 it's a label definition read the label name: @@ -121,13 +121,13 @@ look at second byte of label find location in label table ;BA -;im;cd;cd;cd;cd;cd;cd;cd;cd +;im;00;00;42;00;00;00;00;00 ;+B ;BA ;AC ;sd store the address there -;jm;cd;cd;cd;cd skip to newline +;jm;a8;05;00;00 skip to newline unused padding ;00;00;00;00;00;00;00;00;00;00;00;00;00;00;00;00 @@ -157,36 +157,38 @@ let's read it one byte at a time, storing the full number in RBP ;sy ;im;88;00;40;00;00;00;00;00 +;BA ;zA;lb ;BA ;im;30;00;00;00;00;00;00;00 -;cm;jl;cd;cd;cd;cd not 0-9 +;cm;jg;2e;00;00;00 not 0-9 ;im;39;00;00;00;00;00;00;00 -;cm;jg;cd;cd;cd;cd not 0-9 +;cm;jl;1b;00;00;00 not 0-9 okay it's 0-9 ;im;d0;ff;ff;ff;ff;ff;ff;ff -;jm;cd;cd;cd;cd +;jm;3c;00;00;00 ;00;00;00;00;00;00;00;00;00;00;00;00 padding ;im;61;00;00;00;00;00;00;00 -;cm;jl;cd;cd;cd;cd not a-f--end loop +;cm;jg;8f;00;00;00 not a-f--end loop ;im;66;00;00;00;00;00;00;00 -;cm;jg;cd;cd;cd;cd not a-f--end loop +;cm;jl;7c;00;00;00 not a-f--end loop ;im;a9;ff;ff;ff;ff;ff;ff;ff ;+B +;BA okay we now have a digit in RBX ;AR ;