-1
section .data

section .text

global _start


_start:
    mov eax, loop ; eax <- addr of loop
    mov ebx, new
    mov ecx, new   
    mov esi, 2
loop:
    mov edx, [eax] ; edx <- instruction of loop, but not worked
    mov [ebx], edx 
    add eax, esi
    add ebx, esi
    cmp eax, ecx
    jne loop
    mov ecx, ebx
new:

x86 code picture

What I want in this code is to put the Instruction Hex code of the loop in edx.

If you see here, mov edx and [eax] are stored in the loop, and I think the instruction code is 0x1389108b, but the actual saved value is 0x13cc10cc. I don't know how to get this value 0x1389108b.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
김상엽
  • 15
  • 5

1 Answers1

1

The instruction at loop is 8b 10, and the next instruction is 89 13. However you have set a breakpoint at each of those instructions, so the debugger has overwritten the first byte of each instruction with a breakpoint instruction. The code for a breakpoint is cc, so that’s what your program reads. If you run it without setting breakpoints, you’ll get the value you expect.

prl
  • 11,716
  • 2
  • 13
  • 31
  • GDB has an `hbreak` to use a HW-assisted break point (debug registers instead of `0xcc`) which could also avoid this. I think there's a duplicate on SO of another question about loads seeing the `0xcc`... Yeah, found one where Jester mentioned `hbreak` in an answer. And turns out there are several Visual Studio debugger duplicates. – Peter Cordes May 27 '20 at 09:18