diff --git a/02/in01 b/02/in01 index b287f1b..721ff02 100644 --- a/02/in01 +++ b/02/in01 @@ -1,20 +1,24 @@ || ELF Header -;jm;50;00;00;00 jump over data to code +;jm;cd;cd;cd;cd 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 -;48;b8;00 (0x4000a0) load immediate instruction -;00;00;00;00;00 +;00 (0x4000a0) stores which pass we're on (1 for second pass) +;00;00;00;00;00;00;00 ;00;00;00;00;00;00;00;00 (0x4000a8) used for output -;00;00;' ;'b;'a;'d;' ;'l;'a;'b;'e;'l;\n;00 (0x400090) -;00;00;' 'b;'a;'d;' ;'n;'u;'m;'b;'e;'r;\n;00 (0x40009e) -;00 +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 +;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 ;im;7d;00;40;00;00;00;00;00 pointer to input filename ;JA ;zA O_RDONLY ;IA -;im;02;00;00;00;00;00;00;00 syscall 2, open +;im;02;00;00;00;00;00;00;00 open ;sy ;im;82;00;40;00;00;00;00;00 pointer to output filename @@ -26,6 +30,7 @@ ;im;02;00;00;00;00;00;00;00 open ;sy + begin by writing the elf header. the segment we're loading in includes the ELF header at address 0x400000, so we can just read it from there ;im;04;00;00;00;00;00;00;00 out fd @@ -49,397 +54,415 @@ the segment we're loading in includes the ELF header at address 0x400000, so we ;BA ;im;02;00;00;00;00;00;00;00 -;jg;cd;cd;cd;cd end of file +;cm;jn;cd;cd;cd;cd end of file -calculate the index in the command table +look at first byte of command ;im;88;00;40;00;00;00;00;00 ;BA ;zA;lb -;I;07 -;BA -;im;6a;00;00;00;00;00;00;00 -;cm -;jn;cd;cd;cd;cd skip to newline - -it is a jump instruction. let's read in the label and write it to-- -wait a minute! this is just like our immediate label code. let's just -read the space between the command and the label, and then jump there +it's a label +read the label name. ;im;03;00;00;00;00;00;00;00 ;JA ;im;88;00;40;00;00;00;00;00 ;IA -;im;01;00;00;00;00;00;00;00 +;im;02;00;00;00;00;00;00;00 ;DA ;zA ;sy +convert bytes to an offset +;im;88;00;40;00;00;00;00;00 +;BA +;zA;lb +;