diff options
author | pommicket <pommicket@gmail.com> | 2022-01-06 13:53:52 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-01-06 13:53:52 -0500 |
commit | 8c6b19fdd3a8bca886692056b8f4942b889323c9 (patch) | |
tree | 423b695be1d008205c289d83ae5fd7f48a208c4f /04b/in03 | |
parent | b66a2dbe6b87e75fbb54beda05c00c9f13f84f2c (diff) |
hello world!
Diffstat (limited to '04b/in03')
-rw-r--r-- | 04b/in03 | 82 |
1 files changed, 68 insertions, 14 deletions
@@ -133,6 +133,13 @@ call :string= D=A ?D!0:handle_return +I=:line +J=:"byte" +C=x20 +call :string= +D=A +?D!0:handle_byte + ; set delimiter to newline C=xa @@ -142,6 +149,12 @@ call :string= D=A ?D!0:handle_function +I=:line +J=:"return\n" +call :string= +D=A +?D!0:handle_return + ; check if this is a function call (where we discard the return value) I=:line ; (check for an opening bracket not preceded by a space) @@ -195,6 +208,25 @@ align :local_variable_name reserve d8 +:handle_byte + I=:line + ; 5 = length of "byte " + I+=d5 + call :read_number + ; make sure byte is 0-255 + C=A + D=xff + ?CaD:bad_byte + ; write byte + I=:byte + 1I=C + J=d4 + D=d1 + syscall x1 + !:read_line +:byte + reserve d1 + :handle_call J=I ; just use the rvalue function call code @@ -420,11 +452,18 @@ align :handle_return I=:line - ; "return " is 7 chars long - I+=d7 + ; skip "return" + I+=d6 + C=1I + D=xa + ?C=D:no_return_value + + ; skip ' ' after return + I+=d1 call :set_rax_to_rvalue + :no_return_value J=d4 I=:function_epilogue D=d15 @@ -520,7 +559,7 @@ align C=1I D='' - ?C=D:term_char + ?C=D:term_number D='. ?C=D:term_label D=d58 @@ -952,12 +991,7 @@ align ; put address in rax I=C !:set_rax_to_immediate - -:term_char - I+=d1 - I=1I - !:set_rax_to_immediate - + :number_is_negative reserve d1 @@ -969,6 +1003,8 @@ align ; set rax to the number in the string at rsi :read_number C=1I + D='' + ?C=D:read_char D='- ; set rdx to 0 if number is positive, 1 if negative ?C=D:read_number_negative @@ -981,7 +1017,7 @@ align ; store away negativity C=:number_is_negative 1C=D - + ; check if number starts with 0-9 C=1I D='9 ?C>D:bad_number @@ -1011,6 +1047,12 @@ align :decimal_number_loop_end !:read_number_output +:read_char + I+=d1 + R=1I + I+=d1 + !:read_number_output + :number_starting_with0 I+=d1 C=1I @@ -1018,12 +1060,9 @@ align ?C=D:read_hex_number ; otherwise, it should just be 0 R=d0 - !:read_number_output - + !:read_number_output :read_hex_number - ; 0 followed by something other than x - ?C!D:bad_number I+=d1 ; rbp will store the number R=d0 @@ -1283,6 +1322,15 @@ align xa x0 +:bad_byte + B=:bad_byte_error_message + !:program_error + +:bad_byte_error_message + str Byte not in range 0-255. + xa + x0 + :bad_number B=:bad_number_error_message !:program_error @@ -1532,6 +1580,12 @@ align :"return" str return x20 +:"return\n" + str return + xa +:"byte" + str byte + x20 :"function" str function xa |