diff options
author | H. Peter Anvin <hpa@zytor.com> | 2007-10-22 19:48:06 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2007-10-22 19:48:06 -0700 |
commit | 50620f4a3f78dc8fb51f76633aeeb962e29093d9 (patch) | |
tree | b508bf3842ecef2c3509f12dec57623a05a98083 | |
parent | f41aef273b05a1ed7e2608f019bd8b5d6e561924 (diff) | |
download | nasm-50620f4a3f78dc8fb51f76633aeeb962e29093d9.tar.gz nasm-50620f4a3f78dc8fb51f76633aeeb962e29093d9.tar.bz2 nasm-50620f4a3f78dc8fb51f76633aeeb962e29093d9.zip |
Unbreak particularly tricky hex constants
Unbreak hex constants which contain 'b' or 'd' in potentially tricky
places.
-rw-r--r-- | nasmlib.c | 27 | ||||
-rw-r--r-- | test/radix.asm | 9 |
2 files changed, 29 insertions, 7 deletions
@@ -219,7 +219,8 @@ static int radix_letter(char c) int64_t readnum(char *str, bool *error) { char *r = str, *q; - int32_t radix; + int32_t pradix, sradix, radix; + int plen, slen; uint64_t result, checklimit; int digit, last; bool warn = false; @@ -251,14 +252,26 @@ int64_t readnum(char *str, bool *error) * $<string> (hexadecimal) * <string><radix-letter> */ - if (*r == '0' && (radix = radix_letter(r[1]))) - r += 2; + pradix = sradix = 0; + plen = slen = 0; + + if (*r == '0' && (pradix = radix_letter(r[1])) != 0) + plen = 2; else if (*r == '$') - radix = 16, r++; - else if ((radix = radix_letter(q[-1])) != 0) - q--; - else + pradix = 16, plen = 1; + + if ((sradix = radix_letter(q[-1])) != 0) + slen = 1; + + if (pradix && pradix > sradix) { + radix = pradix; + r += plen; + } else if (sradix && sradix > pradix) { + radix = sradix; + q -= slen; + } else { radix = 10; + } /* * If this number has been found for us by something other than diff --git a/test/radix.asm b/test/radix.asm index c08b550..2c0afab 100644 --- a/test/radix.asm +++ b/test/radix.asm @@ -23,6 +23,15 @@ dd 1010_0101x ; Hex dd $1010_0101 ; Hex + db 0dh ; Hex + db 0bh ; Hex + db 0dx ; Hex + db 0bx ; Hex + db 0hd ; Hex + db 0hb ; Hex + db 0xd ; Hex + db 0xb ; Hex + ;; Floating-point constants ;; All of these should output B4A21147 dd 3.7282705e+4 ; Decimal |