diff options
author | H. Peter Anvin <hpa@zytor.com> | 2008-07-13 15:06:55 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2008-07-13 15:06:55 -0700 |
commit | 570b1c12b600961bb517b9a46cf14533aa54bea6 (patch) | |
tree | b96e750b3321d7474dc3d8dbf5bfb7aeca454cea /test/dtbcd.asm | |
parent | 97b6d5b6769f7112b2d28648991e6ee9b57b4833 (diff) | |
download | nasm-570b1c12b600961bb517b9a46cf14533aa54bea6.tar.gz nasm-570b1c12b600961bb517b9a46cf14533aa54bea6.tar.bz2 nasm-570b1c12b600961bb517b9a46cf14533aa54bea6.zip |
test: add test of nested %rep, BCD constants, and %warning
Add a test case which has smoked out errors in the handling of nested
%rep, BCD constants, and %warning...
Diffstat (limited to 'test/dtbcd.asm')
-rw-r--r-- | test/dtbcd.asm | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/dtbcd.asm b/test/dtbcd.asm new file mode 100644 index 0000000..fcccff6 --- /dev/null +++ b/test/dtbcd.asm @@ -0,0 +1,72 @@ +; +; This is a macro to generate packed BCD constants. +; It is obsoleted by "dt" with a packed BCD value with a "p" +; suffix, but it is included here as a rest of nested %rep. +; +%macro dtbcd 1-*.nolist + %push dtbcd + %rep %0 + %defstr %$abc %1 + %substr %$sign %$abc 1 + %if %$sign == '-' + %substr %$abc %$abc 2,-1 + %xdefine %$sign 0x80 + %elif %$sign == '+' + %substr %$abc %$abc 2,-1 + %xdefine %$sign 0x00 + %else + %xdefine %$sign 0x00 + %endif + %strlen %$abclen %$abc + %defstr %$abclen_str %$abclen + %assign %$pos %$abclen + %assign %$bc 0 + %assign %$ld -1 + %rep %$abclen + %substr %$chr %$abc %$pos + %assign %$pos %$pos-1 + %if %$chr >= '0' && %$chr <= '9' + %if %$ld < 0 + %assign %$ld %$chr-'0' + %assign %$bc %$bc+1 + %if %$bc > 9 + %warning "too many digits in BCD constant" + %exitrep + %endif + %else + db %$ld+((%$chr-'0') << 4) + %assign %$ld -1 + %endif + %elif %$chr == '_' + ; Do nothing... + %else + %error "invalid character in BCD constant" + %exitrep + %endif + %endrep + %if %$ld >= 0 + db %$ld + %endif + %rep 9-%$bc + db 0 + %endrep + db %$sign + %rotate 1 + %endrep + %pop +%endmacro + + dtbcd 123, -456, +789 + dt 123p, -456p, +789p + dtbcd 765432109876543210 + dt 765432109876543210p + dtbcd -765432109876543210 + dt -765432109876543210p + dtbcd +765_432_109_876_543_210 + dt +765_432_109_876_543_210p + dtbcd -765_432_109_876_543_210 + dt -765_432_109_876_543_210p + + ;; Both of these should warn... + dtbcd 8_765_432_109_876_543_210 + dt 8_765_432_109_876_543_210p |