- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图从 Bootloader 编写引导加载程序。编写的代码是
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
mov si, text_string ; Put string position into SI
call print_string ; Call our string-printing routine
jmp $ ; Jump here - infinite loop!
text_string db 'This is my cool new OS!', 0
print_string: ; Routine: output string in SI to screen
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
我不明白的是我们为什么要写jmp$。通过写入jmp$,它进入无限循环。所以,进入无限循环后,最后两行
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
永远不会被执行。
此外,为什么我们要在 ax 中添加 288?
最佳答案
$
是当前指令的地址,所以 jmp $
正在循环自身。这通常是针对 fatal error 而执行的。
这里,加载器不完整,所以它输出一条消息然后循环。 “循环”指令[希望]将被[待添加]的真实代码取代。
用 db
定义的事物或dw
伪操作是数据的定义,并且不是可执行指令[通常——除非您需要汇编器未知的特殊指令]。
因此,如果没有无限循环,您将尝试执行text_string:
处的数据。 ,这会产生未定义/意外的结果,更不用说尝试执行引导 block 的最后部分了。
288
偏移...
启动加载地址为0x07C00
。它正在尝试在位置 (0x07C00 + 4096 + 512)
设置其堆栈段。 --> 0x8E00
。但是,它试图将其放入段寄存器中,因此该值必须右移 4 位。 0x07C0
已经转移并且 288
是 (4096 + 512) >> 4
或0x0120
。 SS
的最终值是 0x07C0 + 0x0120
--> 0x08E0
[地址0x8E00
]
这似乎是错误的(即算术不匹配),但是sp
寄存器设置为4096
,所以 ss:sp
的最后安息之地地址是0x9E00
.
在8086实模式寻址中,所有地址都使用段寄存器和一些偏移量。最终地址为:address = (segreg << 4) + offset
。这是由硬件在以某种方式访问内存的每条指令上完成的。
当您在代码中跳转时,您可以使用 CS
[代码段]寄存器。数据访问使用DS
[数据段]寄存器。和堆栈访问(例如push/pop
或%sp
相对,使用SS
[堆栈段]寄存器。还有一个在字符串指令中使用的ES
[额外段]寄存器。
关于assembly - NASM 引导加载程序中的 jmp $,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35762970/
我正在 C 中的一些 asm 代码中执行相对跳转。我已经让跳转按预期工作,但它会在跳转发生并完成运行代码后立即返回。 #include void function() { asm("jmp
我需要为漏洞利用演示制作一个跳转操作码。 我需要在跳转指令之后跳转到大约 200 个字节。这对于 jmp short 来说太多了。 如果我生成一个带有常规跳转的操作码,jmp $200 我得到这个:
在 AT&T 汇编语法中,文字值必须以 $ 符号为前缀 但是,在内存寻址中,文字值没有$ 符号 例如: mov %eax, -100(%eax) 和 jmp 100 jmp $100, $100 不同
尽管这两个程序都遵守 shellcode 执行所需的相对寻址指令,并且都在执行时打印所需的消息,但当用作 shellcode 时,2nd Sample 失败了。谁能解释这种行为?奇怪的是,与第一个相同
我听说使用 jmp -2 我们可以进行无限循环。这听起来很奇怪,但是在解释了相对跳转需要一个字节之后,下一条指令地址(eip)将比 jmp 地址少 2 个字节。所以,我决定实现它,但我无法让它发挥作用
我偶尔会使用汇编。因此,我需要更专家的帮助来解码我必须处理的一小段代码。 0000: 48 ff 25 61 57 07 00 rex.W jmp QWORD PTR [rip+0x75761
当程序集有像 jmp f 这样的指令时,堆栈和帧指针会发生什么? 我的意思是 - f 是内存中的标签,对吗?我们如何跳转到内存中的不同地址而不更新我们的帧和堆栈指针... 编辑:我说的是 Intel
好的,所以我一直在尝试在汇编/C 中制作一个两步引导加载程序,但我无法让 JMP 工作。起初我以为读取失败了,但是经过以下测试我排除了这种可能性: __asm__ __volatile__(
我正在尝试计算跳转的正确操作码,我在其他线程中看过这个,但我仍然不明白: 我以为公式是desination - (from+5)但它只是不工作,它很远,这是我想跳转到/从的地址: FROM: 6259
我正在尝试编写一个 exe 打包程序/保护程序,作为了解有关汇编程序、C++ 以及 PE 文件工作原理的更多信息的一种方式。我目前已经让它工作了,所以包含 EP 的部分与一个 key 进行异或,并创建
我只是在看我用 C 编写的一个简单 exe 的 .text 部分,我只是想弄清楚一些 x86 操作码的结构。 从我一直在阅读的内容来看,0xe9 似乎是相对跳转 (JMP) 的单字节操作码,但是我不确
所以我在 %eax 有一个地址我想 jmp 到但代码无法编译,有没有办法解决这个问题? movl 0xdeadbeef, %eax jmp %eax ; <--- compile error: typ
对JMP机器指令的十六进制代码转换有疑问。我有我想跳转到的绝对地址,比如“JMP 0x400835”。 首先,这是允许的吗?如果是,相应的十六进制代码是什么? 如果没有,我可以先将地址存储在某个寄存器
在 Google Native Client 的论文中,作者定义了一个 nacljmp如这两条指令: and $0xffffffe0, %eax # Clears the 5 least si
我试图从 Bootloader 编写引导加载程序。编写的代码是 BITS 16 start: mov ax, 07C0h ; Set up 4K stack space after
我被告知尝试使用“jmp”而不是“call”,但是“jmp”不喜欢我..当我跳跃时它不会返回(所以它永远不会退出并且不快乐的日子),但是调用会返回并正常退出。 我很高兴使用“call”,但实际上我应该
我正在尝试用 java 分析一个简单的应用程序,它基本上只打开一个 RMI 接口(interface)并等待消息。当我通过 TIJMP 打开应用程序时,它从头开始报告: 堆:init - 0,已用 -
如何使用jump family指令? 这就是他们所拥有的: JL label "It" jumps if it is less than or if it is not larger than or
在为 x86 平台构建汇编器时,我在编码 JMP 指令时遇到了一些问题: OPCODE INSTRUCTION SIZE EB cb JMP rel8 2 E9 cw
我正在查看 IDA 中的一个程序,试图弄清楚某个函数是如何工作的,这时我遇到了这样的事情: ; C_TestClass::Foo(void) __text:00000000 __ZN14C_TestC
我是一名优秀的程序员,十分优秀!