From 222723bf3079ce4064fe46eaeb1a2375752d6ea5 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Mon, 5 Jun 2017 20:34:58 +0500 Subject: [PATCH] various fixes and additions around datatypes --- Tests/datatypes.nasm | 183 ++++++++++++++++++ atom/language-x86_64-assembly | 2 +- vs code/language-x86_64-assembly | 2 +- .../Syntaxes/x86_64 Assembly.YAML-tmLanguage | 24 ++- .../Syntaxes/x86_64 Assembly.tmLanguage | 36 +++- 5 files changed, 227 insertions(+), 20 deletions(-) create mode 100644 Tests/datatypes.nasm diff --git a/Tests/datatypes.nasm b/Tests/datatypes.nasm new file mode 100644 index 0000000..d436a5f --- /dev/null +++ b/Tests/datatypes.nasm @@ -0,0 +1,183 @@ +; samples from Chapter 3: The NASM Language + + fadd st1 ; this sets st0 := st0 + st1 + fadd st0,st1 ; so does this + + fadd st1,st0 ; this sets st1 := st1 + st0 + fadd to st1 ; so does this + +db, dw, dd, dq, dt, do, dy, dz + + db 0x55 ; just the byte 0x55 + db 0x55,0x56,0x57 ; three bytes in succession + db 'a',0x55 ; character constants are OK + db 'hello',13,10,'$' ; so are string constants + dw 0x1234 ; 0x34 0x12 + dw 'a' ; 0x61 0x00 (it's just a number) + dw 'ab' ; 0x61 0x62 (character constant) + dw 'abc' ; 0x61 0x62 0x63 0x00 (string) + dd 0x12345678 ; 0x78 0x56 0x34 0x12 + dd 1.234567e20 ; floating-point constant + dq 0x123456789abcdef0 ; eight byte constant + dq 1.234567e20 ; double-precision float + dt 1.234567e20 ; extended-precision float + +resb, resw, resd, resq, rest, reso, resy, resz + +buffer: resb 64 ; reserve 64 bytes +wordvar: resw 1 ; reserve a word +realarray resq 10 ; array of ten reals +ymmval: resy 1 ; one YMM register +zmmvals: resz 32 ; 32 ZMM registers + + incbin "file.dat" ; include the whole file + incbin "file.dat",1024 ; skip the first 1024 bytes + incbin "file.dat",1024,512 ; skip the first 1024, and + ; actually include at most 512 + +message db 'hello, world' +msglen equ $-message + +zerobuf: times 64 db 0 + +buffer: db 'hello, world' + times 64-$+buffer db ' ' + + times 100 movsb + +wordvar dw 123 + mov ax,[wordvar] + mov ax,[wordvar+1] + mov ax,[es:wordvar+bx] + + mov eax,[ebx*2+ecx+offset] + mov ax,[bp+di+8] + + mov eax,[ebx*5] ; assembles as [ebx*4+ebx] + mov eax,[label1*2-label2] ; ie [label1+(label1-label2)] + + mov eax,[ebx+8,ecx*4] ; ebx=base, ecx=index, 4=scale, 8=disp + + ; bndstx + ; next 5 lines are parsed same + ; base=rax, index=rbx, scale=1, displacement=3 + bndstx [rax+0x3,rbx], bnd0 ; NASM - split EA + bndstx [rbx*1+rax+0x3], bnd0 ; GAS - '*1' indecates an index reg + bndstx [rax+rbx+3], bnd0 ; GAS - without hints + bndstx [rax+0x3], bnd0, rbx ; ICC-1 + bndstx [rax+0x3], rbx, bnd0 ; ICC-2 + + VDIVPS zmm4, zmm5, dword [rbx]{1to16} ; single-precision float + VDIVPS zmm4, zmm5, zword [rbx] ; packed 512 bit memory + + mov ax,200 ; decimal + mov ax,0200 ; still decimal + mov ax,0200d ; explicitly decimal + mov ax,0d200 ; also decimal + mov ax,0c8h ; hex + mov ax,$0c8 ; hex again: the 0 is required + mov ax,0xc8 ; hex yet again + mov ax,0hc8 ; still hex + mov ax,310q ; octal + mov ax,310o ; octal again + mov ax,0o310 ; octal yet again + mov ax,0q310 ; octal yet again + mov ax,11001000b ; binary + mov ax,1100_1000b ; same binary constant + mov ax,1100_1000y ; same binary constant once more + mov ax,0b1100_1000 ; same binary constant yet again + mov ax,0y1100_1000 ; same binary constant yet again + + db `\u263a` ; UTF-8 smiley face + db `\xe2\x98\xba` ; UTF-8 smiley face + db 0E2h, 098h, 0BAh ; UTF-8 smiley face + + mov eax,'abcd' + + db 'hello' ; string constant + db 'h','e','l','l','o' ; equivalent character constants + + dd 'ninechars' ; doubleword string constant + dd 'nine','char','s' ; becomes three doublewords + db 'ninechars',0,0,0 ; and really looks like this + +__utf16__, __utf16le__, __utf16be__, __utf32__, __utf32le__, __utf32be__ +__float8__, __float16__, __float32__, __float64__, __float80m__, __float80e__, __float128l__, __float128h__ +__Infinity__, __QNaN__, __NaN__, __SNaN__ + +%define u(x) __utf16__(x) +%define w(x) __utf32__(x) + dw u('C:\WINDOWS'), 0 ; Pathname in UTF-16 + dd w(`A + B = \u206a`), 0 ; String in UTF-32 + + db -0.2 ; "Quarter precision" + dw -0.5 ; IEEE 754r/SSE5 half precision + dd 1.2 ; an easy one + dd 1.222_222_222 ; underscores are permitted + dd 0x1p+2 ; 1.0x2^2 = 4.0 + dq 0x1p+32 ; 1.0x2^32 = 4 294 967 296.0 + dq 1.e10 ; 10 000 000 000.0 + dq 1.e+10 ; synonymous with 1.e10 + dq 1.e-10 ; 0.000 000 000 1 + dt 3.141592653589793238462 ; pi + do 1.e+4000 ; IEEE 754r quad precision + +mov rax,__float64__(3.141592653589793238462) +mov rax,0x400921fb54442d18 + +%define Inf __Infinity__ +%define NaN __QNaN__ + dq +1.5, -Inf, NaN ; Double-precision constants + + dt 12_345_678_901_245_678p + dt -12_345_678_901_245_678p + dt +0p33 + dt 33p + + mov ax,seg symbol + mov es,ax + mov bx,symbol + + mov ax,weird_seg ; weird_seg is a segment base + mov es,ax + mov bx,symbol wrt weird_seg + + call (seg procedure):procedure + call weird_seg:(procedure wrt weird_seg) + + dw symbol, seg symbol + + push dword 33 + push strict dword 33 + + times (label-$) db 0 +label: db 'Where am I?' + + times (label-$+1) db 0 +label: db 'NOW where am I?' + +label1 ; some code +.loop + ; some more code + jne .loop + ret +label2 ; some code +.loop + ; some more code + jne .loop + ret + +label3 ; some more code + ; and some more + jmp label1.loop + +label1: ; a non-local label +.local: ; this is really label1.local +..@foo: ; this is a special symbol +label2: ; another non-local label +.local: ; this is really label2.local + jmp ..@foo ; this will jump three lines up + +; non-nasm signed types + +sbyte sword sdword sqword \ No newline at end of file diff --git a/atom/language-x86_64-assembly b/atom/language-x86_64-assembly index 80f0d8a..50805d2 160000 --- a/atom/language-x86_64-assembly +++ b/atom/language-x86_64-assembly @@ -1 +1 @@ -Subproject commit 80f0d8a7da973636a2629f905a73b6697264cfe4 +Subproject commit 50805d22b012c12f0923bce7acbff228424210b0 diff --git a/vs code/language-x86_64-assembly b/vs code/language-x86_64-assembly index 410ac17..b103bda 160000 --- a/vs code/language-x86_64-assembly +++ b/vs code/language-x86_64-assembly @@ -1 +1 @@ -Subproject commit 410ac17b5ec4f4e7b3b507d8a457d27c3d4bb9a5 +Subproject commit b103bda717b5671150936ae063fc16812184f012 diff --git a/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.YAML-tmLanguage b/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.YAML-tmLanguage index 688dfcb..029b999 100644 --- a/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.YAML-tmLanguage +++ b/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.YAML-tmLanguage @@ -18,17 +18,19 @@ repository: constants: patterns: - name: constant.numeric.floating-point - match: \b(([0-9]+\.[0-9]*)(e[+-]?[0-9]+)?|\.?[0-9]+e[+-]?[0-9]+)\b + match: \b((([0-9\_]+\.[0-9\_]*)(e[+-]?[0-9\_]+)?|\.?[0-9\_]+e[+-]?[0-9\_]+))\b + - name: constant.numeric.packed-bcd + match: \b([0-9\_]+p[0-9\_]*)\b - name: constant.numeric.literal - match: (\$[0-9a-f]+)\b + match: (\$0[0-9a-f]+)\b - name: constant.numeric.bin - match: \b[01]+b\b + match: \b((0[by][01\_]+)|([01\_]+[by]))\b - name: constant.numeric.oct - match: \b[0-7]+[oq]\b + match: \b((0[oq][0-7\_]+)|([0-7\_]+[oq]))\b - name: constant.numeric.dec - match: \b[0-9]+\b + match: \b((0d[0-9\_]+)|([0-9\_]+d?))\b - name: constant.numeric.hex - match: \b([0-9a-fA-F]+[hH]|0x[0-9a-fA-F]+)\b + match: \b((0[xh][0-9a-fA-F\_]+)|([0-9a-fA-F\_]+[hH]))\b entities: patterns: @@ -38,6 +40,8 @@ repository: match: '^\s*(%%)?(\w|[\._?])(\w|[_$#@~\.?])*\:' - name: invalid.entity.name.function match: '^\s*([$@~])(\w|[_$#@~\.?])*\:' + - name: entity.label.special + match: \$ - name: entity.directive match: ^\.?(globa?l|extern)\b - name: text.variable @@ -46,13 +50,15 @@ repository: support: patterns: - name: support.type.asm - match: (?i)\b(byte|([doqty]|dq)?word|(d|res)[bdoqtwy]?|ddq|incbin|equ|times|(end|i)?struc|at|iend)\b + match: (?i)\b(s?byte|([doqtyz]|dq|s[dq]?)?word|(d|res)[bdoqtwyz]?|ddq|incbin|equ|times|(end|i)?struc|at|iend)\b - name: support.directive.asm match: (?i)\b(\.?(alignb?|bits|cpu|fpu)|use(16|32|64))\b - name: support.modifier.asm match: \b(strict|nosplit|near|far|abs|rel|seg|wrt|absolute|common)\b - name: support.prefix.asm match: \b([ao](16|32|64))\b + - name: support.function.asm + match: \b__(utf((16|32)([lb]e)?)|float(8|16|32|64|80[me]|128[lh])|Infinity|[QS]?NaN)__\b comments: patterns: @@ -120,10 +126,10 @@ repository: strings: patterns: - name: string.quoted.asm - begin: '["'']' + begin: '["''`]' beginCaptures: '0': { name: punctuation.definition.string.begin.asm } - end: '["'']' + end: '["''`]' endCaptures: '0': { name: punctuation.definition.string.end.asm } patterns: diff --git a/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.tmLanguage b/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.tmLanguage index 4bbf1f9..6e16f26 100644 --- a/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.tmLanguage +++ b/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.tmLanguage @@ -83,37 +83,43 @@ match - \b(([0-9]+\.[0-9]*)(e[+-]?[0-9]+)?|\.?[0-9]+e[+-]?[0-9]+)\b + \b((([0-9\_]+\.[0-9\_]*)(e[+-]?[0-9\_]+)?|\.?[0-9\_]+e[+-]?[0-9\_]+))\b name constant.numeric.floating-point match - (\$[0-9a-f]+)\b + \b([0-9\_]+p[0-9\_]*)\b + name + constant.numeric.packed-bcd + + + match + (\$0[0-9a-f]+)\b name constant.numeric.literal match - \b[01]+b\b + \b((0[by][01\_]+)|([01\_]+[by]))\b name constant.numeric.bin match - \b[0-7]+[oq]\b + \b((0[oq][0-7\_]+)|([0-7\_]+[oq]))\b name constant.numeric.oct match - \b[0-9]+\b + \b((0d[0-9\_]+)|([0-9\_]+d?))\b name constant.numeric.dec match - \b([0-9a-fA-F]+[hH]|0x[0-9a-fA-F]+)\b + \b((0[xh][0-9a-fA-F\_]+)|([0-9a-fA-F\_]+[hH]))\b name constant.numeric.hex @@ -141,6 +147,12 @@ name invalid.entity.name.function + + match + \$ + name + entity.label.special + match ^\.?(globa?l|extern)\b @@ -1552,7 +1564,7 @@ begin - ["'] + ["'`] beginCaptures 0 @@ -1562,7 +1574,7 @@ end - ["'] + ["'`] endCaptures 0 @@ -1624,7 +1636,7 @@ match - (?i)\b(byte|([doqty]|dq)?word|(d|res)[bdoqtwy]?|ddq|incbin|equ|times|(end|i)?struc|at|iend)\b + (?i)\b(s?byte|([doqtyz]|dq|s[dq]?)?word|(d|res)[bdoqtwyz]?|ddq|incbin|equ|times|(end|i)?struc|at|iend)\b name support.type.asm @@ -1646,6 +1658,12 @@ name support.prefix.asm + + match + \b__(utf((16|32)([lb]e)?)|float(8|16|32|64|80[me]|128[lh])|Infinity|[QS]?NaN)__\b + name + support.function.asm +