hello world working! yay!

This commit is contained in:
pommicket 2021-11-09 20:53:55 -05:00
parent 66496d98c4
commit befd4a6435
3 changed files with 56 additions and 10 deletions

16
02/in01
View file

@ -30,7 +30,7 @@ unused padding
;im;02;00;00;00;00;00;00;00 open ;im;02;00;00;00;00;00;00;00 open
;sy ;sy
-- second pass starts here --
begin by writing the elf header. 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 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 ;im;04;00;00;00;00;00;00;00 out fd
@ -54,7 +54,7 @@ the segment we're loading in includes the ELF header at address 0x400000, so we
;BA ;BA
;im;02;00;00;00;00;00;00;00 ;im;02;00;00;00;00;00;00;00
;cm;jn;cd;cd;cd;cd end of file ;cm;jn;61;07;00;00 end of file
look at first byte of command look at first byte of command
;im;88;00;40;00;00;00;00;00 ;im;88;00;40;00;00;00;00;00
@ -213,7 +213,7 @@ now write
;im;01;00;00;00;00;00;00;00 write ;im;01;00;00;00;00;00;00;00 write
;sy ;sy
;jm;cd;cd;cd;cd skip to newline ;jm;c3;03;00;00 skip to newline
unused padding 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
@ -262,7 +262,7 @@ rax has the address to write.
we can just store it in rbp: we can just store it in rbp:
;RA ;RA
then jump to the place where we wrote immediates. then jump to the place where we wrote immediates.
;jm;cd;cd;cd;cd ;jm;d5;fe;ff;ff
unused padding 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
@ -413,7 +413,7 @@ this is a real command
;zA;lb ;zA;lb
;BA ;BA
;im;0a;00;00;00;00;00;00;00 '\n' ;im;0a;00;00;00;00;00;00;00 '\n'
;cm;jn;cd;cd;cd;cd not a newline--keep looping ;cm;jn;ae;ff;ff;ff not a newline--keep looping
;jm;be;f8;ff;ff go back to read next command ;jm;be;f8;ff;ff go back to read next command
unused padding unused padding
@ -424,7 +424,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
;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
-- end of file -- -- end of file (0x400916) --
lseek input fd back to start of file lseek input fd back to start of file
;im;03;00;00;00;00;00;00;00 ;im;03;00;00;00;00;00;00;00
@ -453,7 +453,7 @@ check if we're on the second pass
;BD ;BD
;zA ;zA
;cm;je;cd;cd;cd;cd not the second pass, jump back to do it ;cm;je;bb;f7;ff;ff not the second pass, jump back to do it
okay we're done the second pass. let's exit nicely okay we're done the second pass. let's exit nicely
;zA;JA exit code 0 ;zA;JA exit code 0
@ -6550,7 +6550,7 @@ the formatting changed appropriately.
;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 ;01;90;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

48
02/in02
View file

@ -1,3 +1,47 @@
::hw
jm jm
:-hw :-co jump to code
::hw
'H
'e
'l
'l
'o
',
'
'w
'o
'r
'l
'd
'!
\n
::he end of hello world
::co start of code
//
// now we'll calculate the length of the hello world string
// by subtracting hw from he.
//
im
--he
BA
im
--hw
nA
+B
DA put length in rdx
// okay now we can write it
im
##1.
JA set rdi to 1 (stdout)
im
--hw
IA set rsi to a pointer to "Hello, world!\n"
im
##1. write
sy
im
##0. exit code 0
JA
im
##3c. exit = syscall 0x3c
sy

View file

@ -99,3 +99,5 @@ ret
>c3 >c3
syscall syscall
>0f 05 >0f 05
nop
>90