ASM中的存储器位置寻址 [英] Memory location addressing in ASM

查看:161
本文介绍了ASM中的存储器位置寻址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在某些时候,我尝试了以下方法:(NASM编译器)

  start_of_code:
; ... snip ...

cmp byte [rax],0x66
jae above_label
add byte [rax],0x20
; ... snip ...

above_label:
inc rax
loop start_of_code

gdb在开始时显示以下值 x / 8xb $ rax

  0x12 0x12 0x11 0x20 0x18 0xFE 0x83 0x9b 

前两个迭代是好的, 0x12 按我的预期进行比较,不发生跳转。然而,使用 0x11 cmp 会设置 OF 标志,而不是

我有2现在猜测,要么gdb不首先报告正确的内存位置,0x9b实际上是被比较的地址,或者其他地方。这看起来不太可能,因为添加似乎按照我的预期工作。



或者这可能是一个对齐问题。在cmp之前添加NOP指令似乎以某种方式影响结果。我真的不知道为什么

编辑:
当我尝试时

  mov bl,byte [rax] 

bl 获得 0xcc



这对我没有意义。 gdb不会在 [rax]

0xcc 的任何值class =h2_lin>解决方案

0xcc int3 的机器码,它是软件断点中断。 gdb 在断点处将它放入您的代码中,以便控制回来。它不能很好地读取自身的代码。使用 hbreak 命令来设置不需要修改代码的硬件断点。


I'm trying to write self modifying asm code.

At some point, I try the following : (NASM compiler)

start_of_code:
; ... snip ...

cmp byte [rax], 0x66
jae above_label
  add byte[rax], 0x20
; ... snip ...

above_label:
inc rax
loop start_of_code

gdb shows the following values at start x/8xb $rax :

0x12 0x12 0x11 0x20 0x18 0xfe 0x83 0x9b

The first two iterations are ok, the 0x12 are compared as I expect and no jump take place. With 0x11 however, cmp sets the OF flag instead of the CF and jae is executed

I have 2 guesses at the moment, either gdb doesn't report the right memory location first, 0x9b is in fact the address being compared, or someplace else. This seems unlikely because the add seems to work like I expect.

Or this might be an alignment problem. Adding NOP instructions before the cmp does seem to affect the outcome in some way. I really have no clue why

edit : When I try

mov bl, byte [rax]

bl gets 0xcc

This doesn't make sense to me. gdb doesn't report any value of 0xcc anywhere near [rax]

解决方案

0xcc is the machine code for int3 which is the software breakpoint interrupt. gdb places this into your code at breakpoints so it gets control back. It doesn't play well with code that reads itself. Use the hbreak command instead, to set a hardware breakpoint that doesn't need to modify your code.

这篇关于ASM中的存储器位置寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆