前往
大廳
主題

病毒開發(4) - 組合語言概述與超詳細ㄉHello World解釋

虛鹿 | 2022-02-02 17:50:38 | 巴幣 3442 | 人氣 1207

蠻喜歡這首的,就推薦給諸君ㄅ~(^ ^)

最近為了學習更接近底層的病毒,
於是我花了幾天學了Assembly的基礎觀念。

嗯….但該怎麼講呢~
總覺得一切都比我想像的還要複雜,
概念複雜且真的很難以上手…..( ゚д゚)
而光是要解釋今天要介紹的Hello World,
就花了窩快兩天的說…..OwO

這一兩天之中,
窩盡可能的利用閒餘的時間學習相關概念,
結果:

    過年被灌酒導致的宿醉 +  機掰語法的荼毒

結果害我這幾天頭都好痛,
一整個San值狂掉的說…..(T_T)
真的怕、超怕、簡直怕爆。

好啦,言歸正傳,
日後的文章有部分應該會用到Assembly,
建議對電腦病毒有興趣的巴友也去學一下,
以免想學卻不懂我在工三小。
當然,前提是窩還沒有被組語玩的話。

關於Assembler的部分,
我選擇的是TASM(Borland Turbo Assembler)。
而不同Assembler能接受的語法也不太一樣,
關於這點還請諸君多加留意。

接著,
讓虛鹿來介紹的一下基本的暫存器指令,
Mov: 賦值
Add: 暫存器之間相加。
Lea: 賦予某地址給暫存器。
Jmp: 類似C語言的GoTo的概念。
Push: 將東東放入Stack。
Pop:  將東東取出Stack。

其餘關於的暫存器概念,
就請參考虛鹿的筆記:
(窩在這方面是新手,故資訊可能不太完整。



畢竟每個語言的必備範例都是Hello World,
那~麼~呢~
就讓窩帶諸君看看組語版本的Hello world吧:

嗯嗯~度的~( ̄∇ ̄)
你眼睛沒有花掉!也沒有精神分裂!
那堆code就是組合語言的Hello World呦!
我當時的心情大概跟諸君現在的感受差不多,
最靠北的是,原版的註釋寫的不夠清楚,
我當下的驚嚇程度大概跟這隻貓差不多:

以下這些程式碼就是Hello World的原始碼,
每行都有加上虛鹿的備註的註解,
以便諸君複製或是慢慢思考。
註釋的部分,窩全部都是用英文寫的,
因為TASM GUI不支援外文字,
加上本鹿認為用英文解釋才不易使原意失真,
而這肯定是網路上最清楚的Hello World解釋。

[#] Hello World, Assembly 虛鹿註解 Ver:
; Annotation made by Falsedeer, in 2022/2/2
; Hello World in Assembly

; Self definded code stegment
data segment
    ; define byte variable as the name 'msg'
    ; Dollar-Sign marks the end of the string.
    msg db 'Hello World!','$'
data ends

code segment
    ; assume tells the assembler which segment register to use for accessing a segment
    assume cs:code, ds:data
start: ; The program runs as it supposed to and the output is all the elements of the array printed.
    mov ax, data       ; Move address of data to ax register
    mov ds, ax          ; Move value of ax to ds(data segment register)
                                ; lea moving address of specified data to register / mov moving specified value to register.
    lea dx, msg         ; moving address of var:msg to dx register
    mov ah, 09h        ; Calling funtion(DOS function code) of printing screen to output the shits stored in ds.
                                 ; 09h symbols printing value to screen.
    int 21h                  ; software interupt, calling ah register (pointing to print string)
    mov ah, 4ch        ; Calling function(DOS function code) of exiting program safely
                                 ; 4ch symbols exit program
    int 21h                  ; software interupt, calling ah register (pointing to exit program safely)
code ends

end start   ; end symbols the EOF of program, start points the entry point for assembler

以上這堆就是組合語言的Hello World,
有興趣的還請自行服用。

[#]虛鹿再補充幾點:

1. int 21h 對照表可對應:
mov ah, 09h
int 21h
的mov ah, 09h的部分,
裡面的數值是系統功能的代號(如上例:09h),
而int 21h則是造成software interrupt去執行被指定的功能。

2. 執行組合語言需要先assemble再link,
而這部分VScode做的超爛!!!
本鹿真心不推薦,
我認為TASM GUI在編譯或是執行都更優秀。
畢竟vscode只是編程介面的顏色漂亮而已,
用它寫Assembly真的是機掰難用。

3. 剛剛分享的Hello World,
在成功編譯並執行後的畫面如下:

沒錯!這就是總長28行,
超過1300字的hello world原始碼的輸出結果!
(含虛鹿加上的註釋
就是如此ㄉ樸實無華且枯燥的說~( ̄∇ ̄)


今天就先講到這邊,
我要去看A Jie直播惡靈古堡惹~
下次有空在分享組語寫成的病毒給諸君呦~
\(≧▽≦)/
送禮物贊助創作者 !
0
留言

創作回應

OKHand
組語真滴難[e26]
2022-02-02 22:26:47
虛鹿
難到靠北
2022-02-05 23:54:47
村村
真男人
2022-02-03 00:05:27
虛鹿
組語真的怕
2022-02-05 23:54:38
術業有專攻
2022-02-04 11:10:20
虛鹿
或許吧(?
2022-02-05 23:54:20

更多創作