顯示具有 Assembly 標籤的文章。 顯示所有文章
顯示具有 Assembly 標籤的文章。 顯示所有文章

2024年10月28日 星期一

rappel - Assembly REPL

官方網址:
https://github.com/yrp604/rappel

rappel提供了一個 assembly的交互式介面環境,可以在執行完指令後馬上看到暫存器狀態的變化,用來嘗試一些指令非常好用。

編譯完後可從./bin/rappel執行,Ctrl + d 退出程序:

./bin/rappel
rax=0000000000000000 rbx=0000000000000000 rcx=0000000000000000
rdx=0000000000000000 rsi=0000000000000000 rdi=0000000000000000
rip=0000000000400001 rsp=00007ffd6bf14b30 rbp=0000000000000000
 r8=0000000000000000  r9=0000000000000000 r10=0000000000000000
r11=0000000000000000 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
[cf=0, zf=0, of=0, sf=0, pf=0, af=0, df=0]
cs=0033  ss=002b  ds=0000  es=0000  fs=0000  gs=0000            efl=00000202

mov rax, 0x10
rax=0000000000000010 rbx=0000000000000000 rcx=0000000000000000
rdx=0000000000000000 rsi=0000000000000000 rdi=0000000000000000
rip=0000000000400006 rsp=00007ffd6bf14b30 rbp=0000000000000000
 r8=0000000000000000  r9=0000000000000000 r10=0000000000000000
r11=0000000000000000 r12=0000000000000000 r13=0000000000000000
r14=0000000000000000 r15=0000000000000000
[cf=0, zf=0, of=0, sf=0, pf=0, af=0, df=0]
cs=0033  ss=002b  ds=0000  es=0000  fs=0000  gs=0000            efl=00000202

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則代表後面@@:的位置。