| 1 |
jmp near dword [0] |
| 2 |
jmp far dword [0] |
| 3 |
|
| 4 |
mov bx,ax ; general register to general register |
| 5 |
mov [char],al ; general register to memory |
| 6 |
mov dl,32 ; immediate value to general register |
| 7 |
mov cr3,ebx ; general register to control register |
| 8 |
|
| 9 |
xchg ax,bx ; swap two general registers |
| 10 |
xchg al,[char] ; swap register with memory |
| 11 |
|
| 12 |
push ax ; store general register |
| 13 |
push es ; store segment register |
| 14 |
pushw [bx] ; store memory |
| 15 |
push 1000h ; store immediate value |
| 16 |
|
| 17 |
imul ax,[si],10 ; memory by immediate value to register |
| 18 |
|
| 19 |
bt ax,15 ; test bit in register |
| 20 |
bts word [bx],15 ; test and set bit in memory |
| 21 |
|
| 22 |
bswap edx ; swap bytes in register |
| 23 |
|
| 24 |
jmp 100h ; direct near jump |
| 25 |
jmp 0FFFFh:0 ; direct far jump |
| 26 |
jmp ax ; indirect near jump |
| 27 |
jmp pword [ebx] ; indirect far jump |
| 28 |
|
| 29 |
movs byte [di],[si] ; transfer byte |
| 30 |
movs word [es:di],[ss:si] ; transfer word |
| 31 |
movsd ; transfer double word |
| 32 |
|
| 33 |
cmpxchg8b [bx] ; compare and exchange 8 bytes |
| 34 |
|
| 35 |
movq2dq xmm0,mm1 ; move from MMX register to SSE register |
| 36 |
movdq2q mm0,xmm1 ; move from SSE register to MMX register |
| 37 |
|
| 38 |
enter 2048,0 ; enter and allocate 2048 bytes on stack |
| 39 |
|
| 40 |
mov [rip+3],sil ; manual RIP-relative addressing |
| 41 |
|
| 42 |
blendvps xmm3,xmm7,xmm0 ; blend according to mask |
| 43 |
vgatherqps xmm0,[xmm2],xmm3 ; gather two floats |
| 44 |
vgatherqps xmm0,[ymm2+64],xmm3 ; gather four floats |
| 45 |
vfmsub231ps ymm1,ymm2,ymm3 ; multiply and subtract |
| 46 |
vfnmadd132sd xmm0,xmm5,[ebx] ; multiply, negate and add |
| 47 |
vpermil2ps ymm0,ymm3,ymm7,ymm2,0 ; permute from two sources |
| 48 |
|
| 49 |
vscatterdps [eax+xmm1]{k1},xmm0 ; scatter four floats |
| 50 |
vscatterdpd [ymm3*8]{k3},zmm0 ; scatter eight doubles |
| 51 |
|
| 52 |
dd sum |
| 53 |
x = 1 |
| 54 |
x = x+2 |
| 55 |
sum = x |
| 56 |
|
| 57 |
|
| 58 |
if count>0 |
| 59 |
mov cx,count |
| 60 |
rep movsb |
| 61 |
end if |
| 62 |
|
| 63 |
|
| 64 |
if count & ~ count mod 4 |
| 65 |
mov cx,count/4 |
| 66 |
rep movsd |
| 67 |
else if count>4 |
| 68 |
mov cx,count/4 |
| 69 |
rep movsd |
| 70 |
mov cx,count mod 4 |
| 71 |
rep movsb |
| 72 |
else |
| 73 |
mov cx,count |
| 74 |
rep movsb |
| 75 |
end if |
| 76 |
|
| 77 |
repeat 8 |
| 78 |
mov byte [bx],% |
| 79 |
inc bx |
| 80 |
end repeat |
| 81 |
|
| 82 |
|
| 83 |
s = x/2 |
| 84 |
repeat 100 |
| 85 |
if x/s = s |
| 86 |
break |
| 87 |
end if |
| 88 |
s = (s+x/s)/2 |
| 89 |
end repeat |
| 90 |
|
| 91 |
repeat $-$$ |
| 92 |
load a byte from $$+%-1 |
| 93 |
store byte a xor c at $$+%-1 |
| 94 |
end repeat |
| 95 |
|
| 96 |
GDTR dp ? |
| 97 |
virtual at GDTR |
| 98 |
GDT_limit dw ? |
| 99 |
GDT_address dd ? |
| 100 |
end virtual |
| 101 |
|
| 102 |
virtual at 0 |
| 103 |
file 'a.txt':10h,1 |
| 104 |
load char from 0 |
| 105 |
end virtual |
| 106 |
|
| 107 |
virtual at 0 as 'asc' |
| 108 |
times 256 db %-1 |
| 109 |
end virtual |
| 110 |
|
| 111 |
virtual at 0 |
| 112 |
hex_digits:: |
| 113 |
db '0123456789ABCDEF' |
| 114 |
end virtual |
| 115 |
load a byte from hex_digits:10 |
| 116 |
|
| 117 |
bits = 16 |
| 118 |
display 'Current offset is 0x' |
| 119 |
repeat bits/4 |
| 120 |
d = '0' + $ shr (bits-%*4) and 0Fh |
| 121 |
if d > '9' |
| 122 |
d = d + 'A'-'9'-1 |
| 123 |
end if |
| 124 |
display d |
| 125 |
end repeat |
| 126 |
display 13,10 |
| 127 |
|
| 128 |
if ~ defined alpha |
| 129 |
alpha: |
| 130 |
end if |
| 131 |
|
| 132 |
if ~ defined alpha | defined @f |
| 133 |
alpha: |
| 134 |
@@: |
| 135 |
end if |
| 136 |
|
| 137 |
include 'macros.inc' |
| 138 |
|
| 139 |
d equ dword |
| 140 |
NULL equ d 0 |
| 141 |
d equ edx |
| 142 |
|
| 143 |
d equ d,eax |
| 144 |
|
| 145 |
b equ byte |
| 146 |
w equ word |
| 147 |
d equ dword |
| 148 |
p equ pword |
| 149 |
f equ fword |
| 150 |
q equ qword |
| 151 |
t equ tword |
| 152 |
x equ dqword |
| 153 |
y equ qqword |
| 154 |
|
| 155 |
incl fix include |
| 156 |
|
| 157 |
macro tst {test al,0xFF} |
| 158 |
|
| 159 |
macro stos0 |
| 160 |
{ |
| 161 |
xor al,al |
| 162 |
stosb |
| 163 |
} |
| 164 |
|
| 165 |
macro align value { rb (value-1)-($+value-1) mod value } |
| 166 |
|
| 167 |
macro mov op1,op2 |
| 168 |
{ |
| 169 |
if op1 in <ds,es,fs,gs,ss> & op2 in <cs,ds,es,fs,gs,ss> |
| 170 |
push op2 |
| 171 |
pop op1 |
| 172 |
else |
| 173 |
mov op1,op2 |
| 174 |
end if |
| 175 |
} |
| 176 |
|
| 177 |
macro stoschar [char] |
| 178 |
{ |
| 179 |
mov al,char |
| 180 |
stosb |
| 181 |
} |
| 182 |
|
| 183 |
macro movstr |
| 184 |
{ |
| 185 |
local move |
| 186 |
move: |
| 187 |
lodsb |
| 188 |
stosb |
| 189 |
test al,al |
| 190 |
jnz move |
| 191 |
} |
| 192 |
|
| 193 |
macro strtbl name,[string] |
| 194 |
{ |
| 195 |
common |
| 196 |
label name dword |
| 197 |
forward |
| 198 |
local label |
| 199 |
dd label |
| 200 |
forward |
| 201 |
label db string,0 |
| 202 |
} |
| 203 |
|
| 204 |
push 3 |
| 205 |
push 2 |
| 206 |
push 1 |
| 207 |
call foo |
| 208 |
|
| 209 |
macro invoke proc,[arg] |
| 210 |
{ common stdcall [proc],arg } |
| 211 |
|
| 212 |
macro jif op1,cond,op2,label |
| 213 |
{ |
| 214 |
cmp op1,op2 |
| 215 |
j#cond label |
| 216 |
} |
| 217 |
|
| 218 |
macro label name |
| 219 |
{ |
| 220 |
label name |
| 221 |
if ~ used name |
| 222 |
display `name # " is defined but not used.",13,10 |
| 223 |
end if |
| 224 |
} |
| 225 |
|
| 226 |
macro message arg |
| 227 |
{ |
| 228 |
if arg eqtype "" |
| 229 |
local str |
| 230 |
jmp @f |
| 231 |
str db arg,0Dh,0Ah,24h |
| 232 |
@@: |
| 233 |
mov dx,str |
| 234 |
else |
| 235 |
mov dx,arg |
| 236 |
end if |
| 237 |
mov ah,9 |
| 238 |
int 21h |
| 239 |
} |
| 240 |
|
| 241 |
macro ext instr |
| 242 |
{ |
| 243 |
macro instr op1,op2,op3 |
| 244 |
\{ |
| 245 |
if op3 eq |
| 246 |
instr op1,op2 |
| 247 |
else |
| 248 |
instr op1,op2 |
| 249 |
instr op2,op3 |
| 250 |
end if |
| 251 |
\} |
| 252 |
} |
| 253 |
|
| 254 |
ext add |
| 255 |
ext sub |
| 256 |
|
| 257 |
|
| 258 |
macro tmacro [params] |
| 259 |
{ |
| 260 |
common macro params { |
| 261 |
} |
| 262 |
MACRO fix tmacro |
| 263 |
ENDM fix } |
| 264 |
|
| 265 |
|
| 266 |
MACRO stoschar char |
| 267 |
mov al,char |
| 268 |
stosb |
| 269 |
ENDM |
| 270 |
|
| 271 |
postpone |
| 272 |
{ |
| 273 |
code_size = $ |
| 274 |
} |
| 275 |
|
| 276 |
struc point x,y |
| 277 |
{ |
| 278 |
.x dw x |
| 279 |
.y dw y |
| 280 |
} |
| 281 |
|
| 282 |
struc db [data] |
| 283 |
{ |
| 284 |
common |
| 285 |
. db data |
| 286 |
.size = $ - . |
| 287 |
} |
| 288 |
|
| 289 |
rept 5 { in al,dx } |
| 290 |
|
| 291 |
rept 3 counter |
| 292 |
{ |
| 293 |
byte#counter db counter |
| 294 |
} |
| 295 |
|
| 296 |
match +,+ { include 'first.inc' } |
| 297 |
match +,- { include 'second.inc' } |
| 298 |
match a b, 1+2+3 { db a } |
| 299 |
|
| 300 |
V fix { |
| 301 |
macro empty |
| 302 |
V |
| 303 |
V fix } |
| 304 |
V |
| 305 |
|
| 306 |
|
| 307 |
list equ |
| 308 |
|
| 309 |
macro append item |
| 310 |
{ |
| 311 |
match any, list \{ list equ list,item \} |
| 312 |
match , list \{ list equ item \} |
| 313 |
} |
| 314 |
|
| 315 |
define a b+4 |
| 316 |
define b 3 |
| 317 |
rept 1 result:a*b+2 { define c result } |
| 318 |
|
| 319 |
rept 8 n:0 { pxor xmm#n,xmm#n } |
| 320 |
|
| 321 |
|
| 322 |
irps reg, al bx ecx |
| 323 |
{ xor reg,reg } |
| 324 |
|
| 325 |
|
| 326 |
if 0 |
| 327 |
a = 1 |
| 328 |
b equ 2 |
| 329 |
end if |
| 330 |
dd b |
| 331 |
|
| 332 |
|
| 333 |
extrn exit |
| 334 |
extrn '__imp__MessageBoxA@16' as MessageBox:dword |
| 335 |
|
| 336 |
extrn 'printf' as _printf |
| 337 |
printf = PLT _printf |
| 338 |
|
| 339 |
tester? = 0 |
| 340 |
|
| 341 |
space: |
| 342 |
space.x = 1 |
| 343 |
space.y = 2 |
| 344 |
space.color: |
| 345 |
space.color.r = 0 |
| 346 |
space.color.g = 0 |
| 347 |
space.color.b = 0 |
| 348 |
|
| 349 |
space: |
| 350 |
namespace space |
| 351 |
x = 1 |
| 352 |
y = 2 |
| 353 |
color: |
| 354 |
.r = 0 |
| 355 |
.g = 0 |
| 356 |
.b = 0 |
| 357 |
end namespace |
| 358 |
|
| 359 |
|
| 360 |
first: |
| 361 |
.child = 1 |
| 362 |
..other = 0 |
| 363 |
second: |
| 364 |
.child = 2 |
| 365 |
..another = ..other |
| 366 |
|
| 367 |
|
| 368 |
label character:byte |
| 369 |
label char:1 |
| 370 |
|
| 371 |
byte? = 1 ; 8 bits |
| 372 |
word? = 2 ; 16 bits |
| 373 |
dword? = 4 ; 32 bits |
| 374 |
fword? = 6 ; 48 bits |
| 375 |
pword? = 6 ; 48 bits |
| 376 |
qword? = 8 ; 64 bits |
| 377 |
tbyte? = 10 ; 80 bits |
| 378 |
tword? = 10 ; 80 bits |
| 379 |
dqword? = 16 ; 128 bits |
| 380 |
xword? = 16 ; 128 bits |
| 381 |
qqword? = 32 ; 256 bits |
| 382 |
yword? = 32 ; 256 bits |
| 383 |
dqqword? = 64 ; 512 bits |
| 384 |
zword? = 64 ; 512 bits |
| 385 |
|
| 386 |
element A |
| 387 |
linpoly = A + A + 3 |
| 388 |
vterm = linpoly scale 1 * linpoly element 1 ; vterm = 2 * A |
| 389 |
|
| 390 |
db 4 dup 90h ; generate 4 bytes |
| 391 |
db 2 dup ('abc',10) ; generate 8 bytes |
| 392 |
|
| 393 |
macro measured name,string |
| 394 |
local top |
| 395 |
name db string |
| 396 |
top: name.length = top - name |
| 397 |
end macro |
| 398 |
|
| 399 |
measured hello, 'Hello!' ; hello.length = 6 |
| 400 |
|
| 401 |
A equ 1 |
| 402 |
A equ 2 |
| 403 |
|
| 404 |
drop A |
| 405 |
drop A |
| 406 |
|
| 407 |
data1 dw 1 |
| 408 |
buffer1 rb 10h ; zeroed and present in the output |
| 409 |
|
| 410 |
org 400h |
| 411 |
data dw 2 |
| 412 |
buffer2 rb 20h ; not in the output |
| 413 |
|
| 414 |
section 1000h |
| 415 |
data3 dw 3 |
| 416 |
buffer3 rb 30h ; not in the output |
| 417 |
|
| 418 |
virtual at 0 |
| 419 |
hex_digits:: |
| 420 |
db '0123456789ABCDEF' |
| 421 |
end virtual |
| 422 |
load a:byte from hex_digits:10 ; a = 'A' |
| 423 |
|
| 424 |
db "Text" |
| 425 |
key = 7Bh |
| 426 |
repeat $-$$ |
| 427 |
load a : byte from $$+%-1 |
| 428 |
store a xor key : byte at $$+%-1 |
| 429 |
end repeat |
| 430 |
|
| 431 |
load char : byte from const:0 |
| 432 |
|
| 433 |
if $>10000h |
| 434 |
err 'segment too large' |
| 435 |
end if |
| 436 |
calminstruction please? cmd& |
| 437 |
match =do? =not? cmd, cmd |
| 438 |
jyes done |
| 439 |
assemble cmd |
| 440 |
done: |
| 441 |
end calminstruction |
| 442 |
|
| 443 |
please do not display 'Bye!' |
| 444 |
|
| 445 |
macro jmpi target |
| 446 |
if target-($+2) < 80h & target-($+2) >= -80h |
| 447 |
db 0EBh |
| 448 |
db target-($+1) |
| 449 |
else |
| 450 |
db 0E9h |
| 451 |
dw target-($+2) |
| 452 |
end if |
| 453 |
end macro |
| 454 |
|
| 455 |
macro EX? first,second |
| 456 |
match (=SP?), first |
| 457 |
match =HL?, second |
| 458 |
db 0E3h |
| 459 |
else match =IX?, second |
| 460 |
db 0DDh,0E3h |
| 461 |
else match =IY?, second |
| 462 |
db 0FDh,0E3h |
| 463 |
else |
| 464 |
err "incorrect second argument" |
| 465 |
end match |
| 466 |
else match =AF?, first |
| 467 |
match =AF'?, second |
| 468 |
db 08h |
| 469 |
else |
| 470 |
err "incorrect second argument" |
| 471 |
end match |
| 472 |
else match =DE?, first |
| 473 |
match =HL?, second |
| 474 |
db 0EBh |
| 475 |
else |
| 476 |
err "incorrect second argument" |
| 477 |
end match |
| 478 |
else |
| 479 |
err "incorrect first argument" |
| 480 |
end match |
| 481 |
end macro |
| 482 |
|
| 483 |
EX (SP),HL |
| 484 |
|
| 485 |
macro INC? argument |
| 486 |
match [:r:], argument |
| 487 |
db 100b + r shl 3 |
| 488 |
else match (=HL?), argument |
| 489 |
db 34h |
| 490 |
else match (=IX?+d), argument |
| 491 |
db 0DDh,34h,d |
| 492 |
else match (=IY?+d), argument |
| 493 |
db 0FDh,34h,d |
| 494 |
else |
| 495 |
err "incorrect argument" |
| 496 |
end match |
| 497 |
end macro |
| 498 |
|
| 499 |
INC (IX+2) |
| 500 |
|
| 501 |
element IY? |
| 502 |
|
| 503 |
element L? : register + 101b |
| 504 |
|
| 505 |
macro CALL? arguments& |
| 506 |
local cc,nn |
| 507 |
match condition =, target, arguments |
| 508 |
cc = condition - CC |
| 509 |
nn = target |
| 510 |
db 0C4h + cc shl 3 |
| 511 |
else |
| 512 |
nn = arguments |
| 513 |
db 0CDh |
| 514 |
end match |
| 515 |
dw nn |
| 516 |
end macro |