2020年11月19日 星期四

[ASM] Assembly 筆記


參考來源:
https://www.nasm.us/


Assembler Directives


BIST:Specifying Target Processor Mode

用來告訴 Assembler所要產生的程式碼是要在 16-bit mode或 32-bit mode下運行。
16-bit mode寫作 'BITS 16'而 32-bit mode為 'BITS 32'。若沒有指定則預設為32-bit mode。

USE16 and USE32
與BITS 功能相同,用以相容其他assembler。

MASM


.686 (32bit MASM only)

啟用 Pentium Pro的 nonprivileged指令集

.686P (32bit MASM only)

啟用 Pentium Pro所有指令集

.XMM (32bit MASM only)

啟用 SSE指令集

.MODEL (32bit MASM only)

初始 memory model

ASSUME

啟用檢查 register值


Pseudo Instructions


Pseudo Instructions假指令不是真正的 x86機器碼指令,而是給 compiler看的。

DB (and Friends):Declaring Initialized Data

DB, DW, DD, DT, DO, DY and DZ
用來宣告 data

宣告 1 byte data 0x55
db 0x55 ;just the byte 0x55

EQU:Defining Constants

定義某個符號的值,其之後不能被修改

定義 msglen為 'hello, world'字串的長度,其值為 12
message db 'hello, world'
msglen equ $-message

TIMES:Repeating Instructions or Data

TIMES前綴用來重複該 instruction或 data

宣告長度 64 bytes的 buffer
times 64 db 0 


Expressions


$ and $$

$代表此行的開頭位置,$$為此區段的開頭位置

jmp $ ;infinite loop

@@:

@B可以代表前個@@:位置,@F則代表後面@@:的位置。

沒有留言:

張貼留言