diff options
author | pommicket <pommicket@gmail.com> | 2021-11-13 17:24:45 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2021-11-13 17:24:45 -0500 |
commit | 8bbacdc3316a54b5ef5805701098eb8e81d17986 (patch) | |
tree | 0ee2ef75141c7ce0b43072e9c277a0f251bb4584 /03 | |
parent | eb2aadf9bfd14d95e27050bc24c6fb70c10d885e (diff) |
corrections in 03 compiler, better hello world program!
Diffstat (limited to '03')
-rw-r--r-- | 03/Makefile | 2 | ||||
-rw-r--r-- | 03/ex03 | 1 | ||||
-rw-r--r-- | 03/in02 | 145 | ||||
-rw-r--r-- | 03/in03 | 37 |
4 files changed, 176 insertions, 9 deletions
diff --git a/03/Makefile b/03/Makefile index dd06acd..3d71765 100644 --- a/03/Makefile +++ b/03/Makefile @@ -1,4 +1,4 @@ -all: out02 +all: out02 out03 out02: in02 ../02/out01 ../02/out01 out03: out02 in03 @@ -39,3 +39,4 @@ div call A str Here is some text which will be put in the executable! ?CaD:label + @@ -770,6 +770,107 @@ im ##38. ascii '8' je :-=8 read 8 bytes +im +##78. ascii 'x' +je +:-=# +im +##64. ascii 'd' +je +:-=# +im +##27. ascii ' +je +:-=# +// register transfer. start by writing 48 89 +im +--tx +IA +im +##2. +DA +im +--wr +cl +// get index of first register +im +--LI +BA +zA +lb +BA +im +--r# +cl +DA +// get index of first register +im +##2. +BA +im +--LI ++B +BA +zA +lb +BA +im +--r# +cl +<I +03 shift left by 3 +BA +im +##c0. +|B or with 0xc0 +BD +|B or with dest +BA +im +--wb write that byte +cl +jm +:-rl next line +::tx +48 +89 +// get register index of rbx +::r# +im +##41. 'A' +je +:-r0 +im +##42. 'B' +je +:-r3 +im +##43. 'C' +je +:-r1 +im +##44. 'D' +je +:-r2 +im +##49. 'I' +je +:-r6 +im +##4a. 'J' +je +:-r7 +im +##52. 'R' +je +:-r5 +im +##53. 'S' +je +:-r4 +jm +:-!r +::=# // it's a number. im ##2. @@ -1105,6 +1206,10 @@ im ##53. 'S' je :-AS +im +##30. '0' +je +:-A0 // it's a number im ##3. @@ -1404,6 +1509,10 @@ DA im ##8. syscall 8 = lseek sy +BA +im +##400004. ++B add address of start of file + 4 bytes to write relative offset nA negate current address BR +B get relative address @@ -2125,6 +2234,36 @@ re im ##1. re +// return 2 +::r2 +im +##2. +re +// return 3 +::r3 +im +##3. +re +// return 4 +::r4 +im +##4. +re +// return 5 +::r5 +im +##5. +re +// return 6 +::r6 +im +##6. +re +// return 7 +::r7 +im +##7. +re // exit with code in rax ::ex JA @@ -2557,6 +2696,12 @@ DA im ##8. lseek sy +// set line number to 0 +im +--L# +BA +zA +sq // now go back to do the second pass jm :-2p @@ -1,14 +1,35 @@ ; write to stdout -J=d1 -I=:hello_world -D=:hello_world_end -; calculate length by subtracting end from start -D-=I -syscall d1 -J=d42 +B=:hello_world +call :puts +J=d0 syscall x3c :hello_world str Hello, world! xa -:hello_world_end +x0 + +; output null-terminated string in rbx +:puts + call :strlen + I=D + D=A + J=d1 + syscall d1 + return + +; calculate length of string in rbx +; keeps pointer to start of string in rdx, end of string in rsi +:strlen + ; keep pointer to start of string + D=B + I=B + :strlen_loop + C=1I + ?C=0:strlen_loop_end + I+=d1 + !:strlen_loop + :strlen_loop_end + I-=D + A=I + return |