ARMv7 assembly store values in an array -
i'm trying add user inputted number every element in array. had working until realized original array not being updated. simple, thought, store value array , move on life. sadly, doesn't seem quite simple.
as title suggests, i'm using armv7 , writing assembly. i've been using this guide understand basics , have code at. when run example code given here works fine: str r2, [r3]
puts whatever in r2
r3
points at. following attempt same thing gives me signal 11 occurred: sigsegv (invalid memory segment access)
, execution stopped at: 0x0000580c str r3,[r5,#0]
:
@ loop , add value values in array regardless of array length @ setup loop @ r4 comes above , scanf value, i've checked registers , value correct mov r0, #0 ldr r1, =array_b ldr r2, addrarr loop: @ start loop add inputed number every value in array add r3, r2, r0 ldr r3, [r3] add r3, r3, r4 @ add input each index in array add r5, r2, r0 @ pointer location in array str r3, [r5] @ put new value array cmp r0, r1 @ check end of array addne r0, r0, #4 @ not super necessary shows 1 of cool things arm can do, condition math bne loop @ branch if not equal beq doneloop @ branch if equal doneloop: @ end loop
here vars
.align 2 array: .word 0 .word 1 .word 2 .word 3 .word 4 .word 5 .word 6 .word 7 .equ array_b, .-array addrarr: .word array
my understanding str
takes source first , destination second (which different other instructions reason). r5
used calculate in array store value , r3
has value add
instruction. i've checked , value in r5
valid, ie: it's start of array , array_b proper length (32 in case). i've tried doing =array
instead of addrarr
give same value , same segfault message.
this because there historically in systems 2 major kind of memories :
- rom, read memory, cannot written , can store program , constant data
- ram, random access memory, can both read , written to. used store variables.
many systems no use rom directly, instead data can loaded other permanent support, example floppy disc, tape or hard disc ram. in order avoid program writing ram memory wasn't supposed written, ram can divided in multiple areas, using segmented memory.
not system features this, depends on architecture. if segmented memory used, makes processor quit application when try write segment of ram designed read only. appears problem here.
in order solve should declare array, variable , should stocked in ram, precedding .data
.
on other hand executable instructions should placed in read segment marked assembler directive .text
Comments
Post a Comment