Skip to content

Commit

Permalink
+ vex prefixes
Browse files Browse the repository at this point in the history
+ opmask suffixes
+ rounding suffixes
plus some fixes to labels and what not
  • Loading branch information
13xforever committed Nov 24, 2017
1 parent 846016f commit d8463a0
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 24 deletions.
135 changes: 135 additions & 0 deletions Tests/chapter8.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
segment code
..start:
mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,stacktop

mov dx,hello
mov ah,9
int 0x21

mov ax,0x4c00
int 0x21

segment data
hello: db 'hello, world', 13, 10, '$'

segment stack stack
resb 64
stacktop:



org 100h
section .text
start:
; put your code here
section .data
; put data items here
section .bss
; put uninitialized data here


%macro cglobal 1
global _%1
%define %1 _%1
%endmacro

%macro cextern 1
extern _%1
%define %1 _%1
%endmacro

cextern printf

extern _printf
%define printf _printf



global _myfunc
_myfunc:
push bp
mov bp,sp
sub sp,0x40 ; 64 bytes of local stack space
mov bx,[bp+4] ; first parameter to function
; some more code
mov sp,bp ; undo "sub sp,0x40" above
pop bp
ret

extern _printf
; and then, further down...
push word [myint] ; one of my integer variables
push word mystring ; pointer into my data segment
call _printf
add sp,byte 4 ; `byte' saves space
; then those data items...
segment _DATA
myint dw 1234
mystring db 'This number -> %d <- should be 1234',10,0

push word [myint]
push word seg mystring ; Now push the segment, and...
push word mystring ; ... offset of "mystring"
call far _printf
add sp,byte 6


extern _i
mov ax,[_i]

global _j
_j dw 0


proc _nearproc
%$i arg
%$j arg
mov ax,[bp + %$i]
mov bx,[bp + %$j]
add ax,[bx]
endproc

%define FARCODE
proc _farproc
%$i arg
%$j arg 4
mov ax,[bp + %$i]
mov bx,[bp + %$j]
mov es,[bp + %$j + 2]
add ax,[bx]
endproc



global myfunc
myfunc: push bp
mov bp,sp
sub sp,0x40 ; 64 bytes of local stack space
mov bx,[bp+8] ; first parameter to function
mov bx,[bp+6] ; second parameter to function
; some more code
mov sp,bp ; undo "sub sp,0x40" above
pop bp
retf 4 ; total size of params is 4

extern SomeFunc
; and then, further down...
push word seg mystring ; Now push the segment, and...
push word mystring ; ... offset of "mystring"
push word [myint] ; one of my variables
call far SomeFunc


%define PASCAL
proc _pascalproc
%$j arg 4
%$i arg
mov ax,[bp + %$i]
mov bx,[bp + %$j]
mov es,[bp + %$j + 2]
add ax,[bx]
endproc
75 changes: 75 additions & 0 deletions Tests/chapter9.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
global _myfunc
_myfunc:
push ebp
mov ebp,esp
sub esp,0x40 ; 64 bytes of local stack space
mov ebx,[ebp+8] ; first parameter to function
; some more code
leave ; mov esp,ebp / pop ebp
ret

extern _printf
; and then, further down...
push dword [myint] ; one of my integer variables
push dword mystring ; pointer into my data segment
call _printf
add esp,byte 8 ; `byte' saves space
; then those data items...
segment _DATA
myint dd 1234
mystring db 'This number -> %d <- should be 1234',10,0

extern _i
mov eax,[_i]

global _j
_j dd 0

proc _proc32
%$i arg
%$j arg
mov eax,[ebp + %$i]
mov ebx,[ebp + %$j]
add eax,[ebx]
endproc

extern _GLOBAL_OFFSET_TABLE_ ; in ELF
extern __GLOBAL_OFFSET_TABLE_ ; in BSD a.out

func: push ebp
mov ebp,esp
push ebx
call .get_GOT
.get_GOT:
pop ebx
add ebx,_GLOBAL_OFFSET_TABLE_+$$-.get_GOT wrt ..gotpc
; the function body comes here
mov ebx,[ebp-4]
mov esp,ebp
pop ebp
ret

%macro get_GOT 0
call %%getgot
%%getgot:
pop ebx
add ebx,_GLOBAL_OFFSET_TABLE_+$$-%%getgot wrt ..gotpc
%endmacro

lea eax,[ebx+myvar wrt ..gotoff]

mov eax,[ebx+extvar wrt ..got]

global func:function ; declare it as a function
func: push ebp
; etc.

global array:data array.end-array ; give the size too
array: resd 128
.end:

dataptr: dd global_data_item ; WRONG
dataptr: dd global_data_item wrt ..sym

funcptr: dd my_function
funcptr: dd my_function wrt ..sym
9 changes: 7 additions & 2 deletions Tests/registers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ r0l, r1l, r7l, r16l, r18l, r20l, r21l
r0w, r1w, r7w, r16w, r18w, r20w, r21w
r0d, r1d, r7d, r16d, r18d, r20d, r21d
r0, r1, r7, r16, r18, r20, r21
xmm, xmm01, xmm16, xmm20, xmm21
ymm, ymm01, ymm16, ymm20, ymm21
xmm, xmm01
ymm, ymm01
zmm, zmm01, zmm32, zmm40, zmm41
dr4, dr5, dr16, dr21, dr25
cr1, cr5, cr01, dtr
Expand All @@ -19,6 +19,11 @@ t6, t7, tr3, tr4, tr5
;legacy and compatibility?
db0|db1|db2|db3|db6|db7|tr6|tr7|st

;nasm aliases for zmm
xmm16, xmm17, xmm18, xmm19, xmm20, xmm21, xmm22, xmm23, xmm24, xmm25, xmm26, xmm27, xmm28, xmm29, xmm30, xmm31
ymm16, ymm17, ymm18, ymm19, ymm20, ymm21, ymm22, ymm23, ymm24, ymm25, ymm26, ymm27, ymm28, ymm29, ymm30, ymm31


;general purpose
cl, dl, ah, bh, ch, dh
al, bl, cl, dl, dil, sil, bpl, spl, r8l, r9l, r10l, r11l, r12l, r13l, r14l, r15l
Expand Down
11 changes: 9 additions & 2 deletions Tests/sublime-syntax tests/syntax_test_labels.nasm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ la_$#@~.?bel_?
la_$#@~.?bel_?:
.local_label
.local_label:
.123
.1234:

label
; ^^^^^ entity.name.constant
Expand All @@ -31,15 +33,20 @@ la_$#@~.?bel_?:
; ^ punctuation.separator storage.modifier
; ^^^^^^^^^^^ entity.name.constant
; ^ punctuation.separator

..@special_label
; ^^^ punctuation.separator storage.modifier
; ^^^^^^^^^^^^^ entity.name.constant

..@special_label:
; ^^^ punctuation.separator storage.modifier
; ^^^^^^^^^^^^^ entity.name.constant
; ^ punctuation.separator
.123
; ^ punctuation.separator storage.modifier
; ^^^ entity.name.constant
.123:
; ^ punctuation.separator storage.modifier
; ^^^ entity.name.constant
; ^ punctuation.separator

..start
; ^^^^^^^ support.constant
Expand Down
27 changes: 27 additions & 0 deletions Tests/sublime-syntax tests/syntax_test_not_in_docs.nasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; SYNTAX TEST "Packages/User/x86_64 Assembly.tmbundle/Syntaxes/x86_64 Assembly.sublime-syntax"

%pragma
%pragma bluttan
%pragma bluttan blej
%pragma "Hej tomtegubbar"
%define PR asm foobar
%pragma PR
%pragma preproc
%pragma preproc tjo fidelittan preproc
%pragma dbg tjo fidelittan output
%pragma dbgdbg tjo fidelittan debug format
%pragma Dbg Tjo Fidelittan Output
%pragma Dbgdbg Tjo Fidelittan Debug Format

; opmask
VDIVPD zmm0{k1}{z}, zmm1, zmm3 ; conditional vector operation
; broadcasting
VDIVPS zmm4, zmm5, [rbx]{1to16} ; load single-precision float and
; embedded rounding
VCVTSI2SD xmm6, xmm7, {rz-sae}, rax ; round toward zero. note that it
; is used as if a separate operand.
; it comes after the last SIMD operand

mov eax,[nosplit eax] ; eax as base register
mov eax,[nosplit eax*1] ; eax as index register

6 changes: 4 additions & 2 deletions Tests/sublime-syntax tests/syntax_test_numeric.nasm
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ dq $ff
; ^^^ - constant.numeric

dq .0
; ^^ invalid.illegal.constant.numeric
; ^^ - constant.numeric
; ^ entity.name.constant
dq -.0
; ^^ - constant.numeric
; ^ keyword.operator
; ^^ invalid.illegal.constant.numeric
; ^ entity.name.constant
.e10
; ^^^ entity.name.constant
.e-10
Expand Down
2 changes: 1 addition & 1 deletion Tests/valid-avx.asm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ vpmovsxbw|vpmovsxbd|vpmovsxbq|vpmovsxwd|vpmovsxwq|vpmovsxdq
vpmovzxbw|vpmovzxbd|vpmovzxbq|vpmovzxwd|vpmovzxwq|vpmovzxdq
vpmuldq|vpmulhrsw|vpmulhuw|vpmulhw|vpmulld|vpmullw|vpmuludq
vpor|vpsadbw|vpshufb|vpshufd|vpshufhw|vpshuflw|vpsignb|vpsignw|vpsignd
vpslldq|vpsllw|vpslld|vpsllq|vpsraw|vpsrad|vpsrldq|vpsrlw|vpsrld|vpsrlq
vpslldq|vpsllw|vpslld|vpsllq|vpsraw|vpsrad|vpsraq|vpsrldq|vpsrlw|vpsrld|vpsrlq
vpsubb|vpsubw|vpsubd|vpsubq|vpsubsb|vpsubsw|vpsubusb|vpsubusw|vptest
vpunpckhbw|vpunpckhwd|vpunpckhdq|vpunpckhqdq|vpunpcklbw|vpunpcklwd|vpunpckldq|vpunpcklqdq|vpxor

Expand Down

0 comments on commit d8463a0

Please sign in to comment.