title: Assembly - Trying to move byte to memory not working
body: <p>I am trying to modify a string which is stored in memory by changing a byte in it. I'm using movb to this but for some reason, the byte at the given memory location is not changing.</p>
  
  <p>On gdb debugger:</p>
  
  <blockquote>
    <p>14             movb %al, (%r10) # next instr<br>
    (gdb) print /d $al<br>
    $4 = 0<br>
    (gdb) print /c *$r10<br>
    $5 = 47 '/'<br>
    (gdb) s<br>
    16              mov $59, %rax<br>
    (gdb) print /c *$r10<br>
    $6 = 47 '/'<br></p>
  </blockquote>
  
  <p>The code is just:</p>
  
  <pre><code>.globl _start
  .text
  
  _start:
          call chamaexecve
          variaveis:
              .asciz "/bin/bashABBBBCCCC"
  
  
      chamaexecve: 
  
          pop %r10
          xor %rax, %rax
          movb %al, (%r10) # problem happening here
  
          mov $59, %rax
          mov %rsi, %rdi
          mov $0, %rsi
          mov $0, %rdx
  
          syscall
  </code></pre>
  
  <p>And it is being compiled with <code>as -gstabs -o shellf.o shellf.s</code> - <code>ld -N -z execstack  -o shellf shellf.o</code></p>
  
  <p><strong>Edit</strong> To be sure I wasn't making any mistake I deleted the executable and recompiled. The error persists. Another thing I noticed is that if I add a line <code>movb $'r', %al</code> before moving %al to memory, so the <code>'r'</code> is normally printed on memory but for some reason it is not working with the <code>$0</code> value.</p>
  
  <p>I'm running this on a Linux Mint 18.1 "Serena" rolling release, gnu assembler 2.26.1. Here is a print using <code>x/i $rip</code> to show the current instruction:</p>
  
  <p><a href="https://i.stack.imgur.com/yoMvu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yoMvu.png" alt="enter image description here"></a></p>
  
  <p><strong>Edit2</strong>:
  After changing break to tbreak and s to si, I saw it changing from '/' to '\000' finally. So what could be the problem after all s/break/gdb getting messed up?</p>
  
  <blockquote>
    <p>(gdb) tb 14<br>
    Temporary breakpoint 1 at 0x4000cd: file shellf.s, line 14.<br>
    (gdb) run<br>
    Starting program: /home/fabio/criação/nasm-tutorial/shellf <br>
    <br>
    Temporary breakpoint 1, chamaexecve () at shellf.s:14<br>
    14              movb %al, (%r10)<br>
    (gdb) si<br>
    16              mov $59, %rax<br>
    (gdb) print /c *$rsi<br>
    Cannot access memory at address 0x0<br>
    (gdb) print /c *$r10<br>
    $1 = 0 '\000'<br>
    (gdb) <br></p>
  </blockquote>