【发布时间】:2013-07-26 21:16:02
【问题描述】:
例如,在 Assembly x86 中,我们可以使用 .data 条目部分并像这样静态定义数据字节:
MSG db 'CAGA', AAFF
我的问题是,假设我们正在组装成一个平面二进制 (bin) 文件,汇编器如何或做什么来实现将数据插入到二进制文件中。
我想知道,因为我正在尝试反编译,并更好地了解如何使用机器代码编程。
看,我想用机器码编写系统软件,但汇编器抽象出一些机器码概念(如静态数据声明、对齐、指令宽度、语句的结构、操作数或一般代码),我在停顿。
我只是想问一下,关于机器代码,它是如何在这些基础上进行布局的:
程序的 .data 部分是如何静态添加到文件中的,当 CPU 获取指令时,它如何在运行时/处理时使用?例如,在下面这个程序中,它是一个 x86 引导加载程序,在 FASM 上采用 Intel 语法汇编代码,
[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 指令?
基本上,文件中的静态二进制数据字节如何作为代码操作数被移入源索引寄存器?
【问题讨论】:
标签: assembly