From a08fef645e4b2504d7c2109946c90e63ca91b731 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sun, 27 Feb 2022 15:31:02 -0500 Subject: cleaned up comments --- 02/README.md | 3 +++ 02/in01 | 10 +++++----- 03/in02 | 29 +++++++++++++++-------------- 04/in03 | 2 +- 05/README.md | 4 +++- README.md | 2 ++ 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/02/README.md b/02/README.md index 9ba5063..1854baa 100644 --- a/02/README.md +++ b/02/README.md @@ -157,6 +157,9 @@ Numbers cannot appear at the end of a line (this made the compiler simpler to write), so I'm adding a `.` at the end of each one to avoid making that mistake. +The code for `cmp rax, rbx` is now included in all conditional jump instructions +(I kept forgetting to put `cm` before conditional jumps when writing this compiler). + Anything after a command is treated as a comment; additionally `//` can be used for comments on their own lines. I decided to implement this as simply as possible: diff --git a/02/in01 b/02/in01 index 58fcc28..0dfacd8 100644 --- a/02/in01 +++ b/02/in01 @@ -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 (0x400174) -- +-- read a 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 @@ -184,7 +184,7 @@ okay we now have a digit in rbx ;AR ;c non-constant shift -// write shr rax, +// write shr rax, imm8 prefix im -->I IA @@ -651,7 +651,7 @@ im ##43. ascii 'C' je :-]c non-constant shift -// write sar rax, +// write sar rax, imm8 prefix im --]I IA @@ -803,7 +803,7 @@ im --r# cl DA -// get index of first register +// get index of second register im ##2. BA @@ -884,7 +884,7 @@ im cl BA put number in rbx im ---im put immediate in rax +--im emit "mov rax, (immediate)" cl im --1A transfer immediate to output @@ -1000,7 +1000,7 @@ im cl put rax in output jm :-rl -// emit 'B = line[1]', i.e. deal with address of store instruction +// set rbx to register referred to by line[1], i.e. deal with the address of a store instruction ::s@ im ##1. @@ -1173,7 +1173,7 @@ lb BA // note: for this we allow numerical operands, e.g. 'C+=d1' // we don't need this for ::B2 because it's only used for load instructions -// (you don't normally need to dereference numerical literals) +// (you don't normally need to dereference numbers) im ##41. 'A' je @@ -1277,7 +1277,7 @@ BA zA jn if on second pass, :-rl ignore this (read next line) -// first get current address +// get current address im ##4. output fd JA @@ -1303,7 +1303,7 @@ im --LI IA // copy from rsi to rdi until a newline is reached -::lc label copy +::lc label copy loop BI zA lb @@ -1455,9 +1455,9 @@ im JA jm :-s= keep looping -// emit "mov rax, immediate" -- with immediate in rbx +// emit "mov rax, immediate" with immediate in rbx ::im -// first, write prefix +// first, emit the prefix im --IM IA @@ -1574,7 +1574,8 @@ jm jm // conditional jump handling ::?j -// note, we actually put the first operand in rbx and the second in rax. this is because A>0 is more familiar than 00 is more familiar than 0