From 648d9432b6fe42589cecdab0a2b5747cb6145559 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 14 Jul 2021 01:15:10 -0700 Subject: [PATCH] clarify a corner case in 2's complement integers https://merveilles.town/@akkartik/106577885001702701 --- 126write-int-decimal.subx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/126write-int-decimal.subx b/126write-int-decimal.subx index f2754fda..d30cb762 100644 --- a/126write-int-decimal.subx +++ b/126write-int-decimal.subx @@ -263,6 +263,37 @@ test-write-int32-decimal-negative: # . end c3/return +# There's a special bit pattern that corresponds to no 2's complement integer. +# There doesn't seem to be a widespread convention for representing it. +test-write-int32-decimal-indefinite-integer: + # setup + # . clear-stream(_test-stream) + # . . push args + 68/push _test-stream/imm32 + # . . call + e8/call clear-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + # write-int32-decimal(_test-stream, 0x80000000) + # . . push args + 68/push 0x80000000/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call write-int32-decimal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # check-stream-equal(_test-stream, "-(", msg) + # . . push args + 68/push "F - test-write-int32-decimal-indefinite-integer"/imm32 + 68/push "-("/imm32 + 68/push _test-stream/imm32 + # . . call + e8/call check-stream-equal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + # . end + c3/return + test-write-int32-decimal-negative-multiple-digits: # - check that a multi-digit number converts correctly # setup