From 343129a61099f74ab746905a693d7b18ced6b269 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 11 Jan 2022 18:03:09 -0500 Subject: full multiply --- 05/main.b | 5 ++++- 05/tokenize.b | 10 +++++++--- 05/util.b | 29 ++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/05/main.b b/05/main.b index f21438f..b500150 100644 --- a/05/main.b +++ b/05/main.b @@ -88,7 +88,6 @@ function main local tokens fill_in_powers_of_10() - print_powers_of_10() dat_banned_objmacros = 255 dat_banned_fmacros = 255 @@ -142,6 +141,10 @@ function main string a.out byte 0 +; NOTE: this language doesn't have proper support for floating-point numbers, +; but we need to do some float stuff. floats are stored as a 58-bit significand +; and an exponent. the significand ranges from 0 (inclusive) to 0x400000000000000 (exclusive) + function normalize_float argument p_significand argument p_exponent diff --git a/05/tokenize.b b/05/tokenize.b index 3715fc1..1c197a7 100644 --- a/05/tokenize.b +++ b/05/tokenize.b @@ -120,6 +120,8 @@ function tokenize local n local p local data + local significand + local exponent in = pptokens :tokenize_loop @@ -236,9 +238,6 @@ function tokenize out += 2 ; no info data = c goto token_output - :tokenize_float - ; @TODO - byte 0xcc :tokenize_string_literal n = rodata_end_offset - RODATA_OFFSET n += RODATA_ADDR ; address of string @@ -261,6 +260,11 @@ function tokenize out += 2 ; no info data = n goto token_output + :tokenize_float + significand = 0 + exponent = 0 + ; @TODO + byte 0xcc :tokenize_loop_end return 0 diff --git a/05/util.b b/05/util.b index 177c31e..190c736 100644 --- a/05/util.b +++ b/05/util.b @@ -1,4 +1,31 @@ - +; multiply two 64-bit signed numbers to a 128-bit number +function full_multiply_signed + argument a + argument b + argument p_lower + argument p_upper + local lower + local upper + + lower = a * b + ; mov rax, rdx + byte 0x48 + byte 0x89 + byte 0xd0 + ; mov [rbp-48] (upper), rax + byte 0x48 + byte 0x89 + byte 0x85 + byte 0xd0 + byte 0xff + byte 0xff + byte 0xff + + *8p_lower = lower + *8p_upper = upper + return + + function file_error argument name fputs(2, .str_file_error) -- cgit v1.2.3