たとえば、Assembly x86 では、.data エントリ セクションを使用して、次のようにデータ バイトを静的に定義できます。
MSG db 'CAGA', AAFF
私の質問は、フラット バイナリ (bin) ファイルにアセンブルしていると仮定して、バイナリ ファイルにデータを挿入するためにアセンブラがどのように、または何を行うかに関するものです。
私は逆コンパイルを試みているので知りたいのですが、機械語プログラミングの操作方法についても理解を深めたいと思っています。
システムソフトウェアをマシンコードでコーディングしたいのですが、アセンブラーはいくつかのマシンコードの概念 (静的データ宣言、アラインメント、命令幅、ステートメントの構造化、オペランド、またはコード全般など) を抽象化し、行き詰まっています。
私は単純に、マシン コードに関して、これらの基本事項の中でどのように配置されているかを尋ねています。
プログラムの .data 部分はどのようにファイルに静的に追加され、CPU が命令をフェッチするときにランタイム/処理時間でどのように使用されるのでしょうか? たとえば、次のプログラムでは、FASM 上の Intel 構文アセンブリ コードの x86 ブートローダーであり、
[BITS 16] ;Tells the assembler that its a 16 bit code
[ORG 0x7C00] ;Origin, tell the assembler that where the code will
;be in memory after it is been loaded
MOV SI, HelloString ;Store string pointer to SI
CALL PrintString ;Call print string procedure
JMP $ ;Infinite loop, hang it here.
PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AH, 0x0E ;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00 ;Page no.
MOV BL, 0x07 ;Text attribute 0x07 is lightgrey font on black background
INT 0x10 ;Call video interrupt
RET ;Return to calling procedure
PrintString: ;Procedure to print string on screen
;Assume that string starting pointer is in register SI
next_character: ;Lable to fetch next character from string
MOV AL, [SI] ;Get a byte from string and store in AL register
INC SI ;Increment SI pointer
OR AL, AL ;Check if value in AL is zero (end of string)
JZ exit_function ;If end then return
CALL PrintCharacter ;Else print the character which is in AL register
JMP next_character ;Fetch next character from string
exit_function: ;End label
RET ;Return from procedure
;Data
HelloString db 'Hello World', 0 ;HelloWorld string ending with 0
TIMES 510 - ($ - $$) db 0 ;Fill the rest of sector with 0
DW 0xAA55 ;Add boot signature at the end of bootloader
" HelloString db 'Hello World', 0 " は 0 と 1 として bin ファイルに静的に挿入されますが、マシン コードでは、文字列ポインターを格納することにより、静的バイナリ データが MOV SI 命令のオペランドとしてどのように追加されるのでしょうか。登記簿上の住所?
基本的に、ファイル内のスタティック バイナリ データ バイトをコード オペランドとして実行し、ソース インデックス レジスタに移動するにはどうすればよいでしょうか?