Saturday, 15 February 2014

ARMv7 assembly store values in an array -


I am trying to add a user input number to each element in an array. By the time I did not realize that the original array was not being updated, I was doing everything. Simple, I thought, store values ​​back into the array and proceed with life. Sadly, it does not seem very easy

As the title suggests, I am writing ARMv7 and Assembly. I'm using the basics to understand and see some good code when I run the example code here, it works fine: str r2, [r3] What is the number at r2 in r3 ? The following is my attempt to do a job that generates a signal 11: SIGSEGV (invalid memory segment access) and execution stopped: 0x0000580C STR r3, [r5, #] 0] :

  @ loop and add value to all the values ​​in the array, regardless of the array length @setup loop @ r4 comes from above and scanf value, i register and Value correct mov r0, # 0 ldr r1, = array_b ldr r2, addrArr loop: add array r3, r2, r0 ldr r3, [r3] in input value of each value Start adding to add, add input to r3, r2, r0 @ indicator in r3, r3, r4 @ indicator array array, r3, r3, r4, add new values ​​array r r, r1 @ sir r3, [r5] @ dollar Check for end of adnex r0, r0, # 4 @ is super important, but it shows one of the cool things that ARM can do, position math bne loop @ branch if not equal, then loop @ branch if i L doneLoop: @ and loop  

These are the wars

  .lign 2 array: .word 0. Word1 .word2 Keywords3. Word 4. Word 5. Word 6. Term 7 .ap array_b. -ArrayRR: .word-array  

I understand that the str takes the source first and the destination is second (which is different from other instructions for some reason ) Then the value of r5 is used to calculate the value and for value from the r3 in the addition instruction. I checked and the value in r5 is valid, that is: it is the beginning of the array and array_b is the proper length (32 in this case). I have tried to addrArr instead of = array , but they attach the same value and the same segfault message.

This is because the system has historically been remembered in two major types of memories:

  • Rome, read-only memory, can not be written and can only store programs and continuous data
  • Both RAM, random access memory can be read and written It is used to store variables.

Many systems do not use the ROM directly, instead the data can be loaded with other enduring support, for example a floppy disk, tape or RAM memory in a hard disk RAM To avoid writing a program that was not to be written, RAM can be divided into many areas using fragmented memory .

All the system features it, so it really depends on architecture. If fragmented memory is used, then it basically exits the processor from the application, when you try to write a segment of that RAM which is designed to be read only it actually appears to be your problem it happens.

To solve this, you should declare your array, which is a variable and should be kept in RAM, it is called .data .


No comments:

Post a Comment