title: This assembly code makes nothing
body: <p>I'm working in a C file, which is something like this:</p>
  
  <pre><code>    #define v2      0x560000a0
      int main(void)
      {
          long int v1;
          v1 = ioread32(v2);
          return 0;
      }
  </code></pre>
  
  <p>and I've extracted this part to write it in assembly: </p>
  
  <pre><code>int main ()
  {
      extern v1,v2;
      v1=ioread32(v2);
      return 0;
  }
  </code></pre>
  
  <p>I'm trying to write the value of v2 in v1 using assembly code for armv4. Using </p>
  
  <pre><code>arm-linux-gnueabi-gcc -S -march=armv4 assembly_file.c
  </code></pre>
  
  <p>I get this code:</p>
  
  <pre><code>.arch armv4
  .eabi_attribute 27, 3
  .fpu vfpv3-d16
  .eabi_attribute 20, 1
  .eabi_attribute 21, 1
  .eabi_attribute 23, 3
  .eabi_attribute 24, 1
  .eabi_attribute 25, 1
  .eabi_attribute 26, 2
  .eabi_attribute 30, 6
  .eabi_attribute 34, 0
  .eabi_attribute 18, 4
  .file   "txind-rsi.c"
  .text
  .align  2
  .global main
  .type   main, %function
  
  main:
  @ Function supports interworking.
  @ args = 0, pretend = 0, frame = 0
  @ frame_needed = 1, uses_anonymous_args = 0
  stmfd   sp!, {fp, lr}
  add fp, sp, #4
  ldr r3, .L2
  ldr r3, [r3, #0]
  mov r0, r3
  bl  ioread32
  mov r2, r0
  ldr r3, .L2+4
  str r2, [r3, #0]
  mov r3, #0
  mov r0, r3
  sub sp, fp, #4
  ldmfd   sp!, {fp, lr}
  bx  lr
  
  .L3:
  .align  2
  
  .L2:
  .word   v1
  .word   v2
  .size   main, .-main
  .ident  "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
  .section    .note.GNU-stack,"",%progbits
  </code></pre>
  
  <p>I use that code to put it back inside the C file this way:</p>
  
  <pre><code>asm volatile(
      "stmfd  sp!, {fp, lr}\n"
      "add    fp, sp, #4\n"
      "ldr    r3, =v1\n"
      "ldr    r3, [r3, #0]\n"
      "mov    r0, r2\n"
      "ldr    r3, =v2\n"
      "str    r2, [r3, #0]\n"
      "sub    sp, fp, #4\n"
      "ldmfd  sp!, {fp, lr}\n"
      "bx lr"
  );
  </code></pre>
  
  <p>The code doesn't do anything. </p>
  
  <p>In fact, it stops the target working.
  Does anyones know why?</p>
  
  <p>EDITED:
  After reading your answers I have another question: 
  How would I put a constant value in a register?. The code in C would be this:</p>
  
  <pre><code>#define v2      0x560000a0
  int main(void)
  {
      long int value = 0x0000ffff;
      long int v1;
      v1 = ioread32(v2);
      iowrite32(v2,value);
      return 0;
  }
  </code></pre>
  
  <p>I've tried this:</p>
  
  <pre><code>asm volatile("mov r3, #value");
  </code></pre>
  
  <p>and I get an assembler message: "value symbol is in a different section";
  I've also tried </p>
  
  <pre><code>asm volatile("mov r3, #0x0000ffff);
  </code></pre>
  
  <p>and the assembler message is:
  "invalid constant(ffff) after fixup". And after reading this: <a href="https://stackoverflow.com/questions/10261300/invalid-constant-after-fixup">Invalid constant after fixup?</a>
  I don't know how I can put that value into r3, as it seems I can't do it with mov.I'm using armv4, not armv7. And this solution proposed in the link, doesn't work for me:</p>
  
  <pre><code>asm volatile("ldr   r3, =#0000ffff\n");
  </code></pre>