Skip to content

Commit

Permalink
various fixes and additions around datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
13xforever committed Jun 5, 2017
1 parent f5615e3 commit 222723b
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 20 deletions.
183 changes: 183 additions & 0 deletions Tests/datatypes.nasm
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion atom/language-x86_64-assembly
2 changes: 1 addition & 1 deletion vs code/language-x86_64-assembly
24 changes: 15 additions & 9 deletions x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
36 changes: 27 additions & 9 deletions x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,43 @@
<array>
<dict>
<key>match</key>
<string>\b(([0-9]+\.[0-9]*)(e[+-]?[0-9]+)?|\.?[0-9]+e[+-]?[0-9]+)\b</string>
<string>\b((([0-9\_]+\.[0-9\_]*)(e[+-]?[0-9\_]+)?|\.?[0-9\_]+e[+-]?[0-9\_]+))\b</string>
<key>name</key>
<string>constant.numeric.floating-point</string>
</dict>
<dict>
<key>match</key>
<string>(\$[0-9a-f]+)\b</string>
<string>\b([0-9\_]+p[0-9\_]*)\b</string>
<key>name</key>
<string>constant.numeric.packed-bcd</string>
</dict>
<dict>
<key>match</key>
<string>(\$0[0-9a-f]+)\b</string>
<key>name</key>
<string>constant.numeric.literal</string>
</dict>
<dict>
<key>match</key>
<string>\b[01]+b\b</string>
<string>\b((0[by][01\_]+)|([01\_]+[by]))\b</string>
<key>name</key>
<string>constant.numeric.bin</string>
</dict>
<dict>
<key>match</key>
<string>\b[0-7]+[oq]\b</string>
<string>\b((0[oq][0-7\_]+)|([0-7\_]+[oq]))\b</string>
<key>name</key>
<string>constant.numeric.oct</string>
</dict>
<dict>
<key>match</key>
<string>\b[0-9]+\b</string>
<string>\b((0d[0-9\_]+)|([0-9\_]+d?))\b</string>
<key>name</key>
<string>constant.numeric.dec</string>
</dict>
<dict>
<key>match</key>
<string>\b([0-9a-fA-F]+[hH]|0x[0-9a-fA-F]+)\b</string>
<string>\b((0[xh][0-9a-fA-F\_]+)|([0-9a-fA-F\_]+[hH]))\b</string>
<key>name</key>
<string>constant.numeric.hex</string>
</dict>
Expand Down Expand Up @@ -141,6 +147,12 @@
<key>name</key>
<string>invalid.entity.name.function</string>
</dict>
<dict>
<key>match</key>
<string>\$</string>
<key>name</key>
<string>entity.label.special</string>
</dict>
<dict>
<key>match</key>
<string>^\.?(globa?l|extern)\b</string>
Expand Down Expand Up @@ -1552,7 +1564,7 @@
<array>
<dict>
<key>begin</key>
<string>["']</string>
<string>["'`]</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
Expand All @@ -1562,7 +1574,7 @@
</dict>
</dict>
<key>end</key>
<string>["']</string>
<string>["'`]</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down Expand Up @@ -1624,7 +1636,7 @@
<array>
<dict>
<key>match</key>
<string>(?i)\b(byte|([doqty]|dq)?word|(d|res)[bdoqtwy]?|ddq|incbin|equ|times|(end|i)?struc|at|iend)\b</string>
<string>(?i)\b(s?byte|([doqtyz]|dq|s[dq]?)?word|(d|res)[bdoqtwyz]?|ddq|incbin|equ|times|(end|i)?struc|at|iend)\b</string>
<key>name</key>
<string>support.type.asm</string>
</dict>
Expand All @@ -1646,6 +1658,12 @@
<key>name</key>
<string>support.prefix.asm</string>
</dict>
<dict>
<key>match</key>
<string>\b__(utf((16|32)([lb]e)?)|float(8|16|32|64|80[me]|128[lh])|Infinity|[QS]?NaN)__\b</string>
<key>name</key>
<string>support.function.asm</string>
</dict>
</array>
</dict>
</dict>
Expand Down

0 comments on commit 222723b

Please sign in to comment.