Message from @meratrix
Discord ID: 430161918938841088
oh shit
I forgot to change that
lol
That's why I said, write the C code first.
I was using my previous one as a template because that also had a loop, and that was for a string.
I mean, I still have a segfault, but that would have caused other problems obviously.
@meratrix why more js
js should be left in a ditch
cause js is best bs
and never be talked about
JS == BS
Shitting on JS is the only way some JS programmers can cope with their job.
Keeps them from offing themselves.
<:think_hang:378717098903470080>
<:super_edgy:426099058466095119>
Then why do some JS coders spend so many time shitting on other lower level languages?
^
Because they don't know any better.
@Deleted User Still doesn't work, ugh. Please end my misery.
```
.data
print: .asciz "%d\n"
scan: .asciz "%d"
array: .skip 20
a: .word
.text
.global main
main:
push {fp, lr}
mov r6, #0 /* r6 <- 0 */
mov r3, #0 /* r3 <- 0 */
ldr r4, =array /* r4 <- array */
in_loop:
cmp r3, #5 /* compare r3 and 5 */
bge in_loop_end /* branch to in_loop_end if r3 >= 5 */
ldr r0, =scan /* r0 <- &scan */
ldr r1, =a /* r1 <- a */
bl scanf /* calls scanf */
ldr r1, =a /* r1 <- a */
add r4, r4, #1 /* r4 <- r4 + 1 */
add r3, r3, #1 /* r3 <- r3 + 1 */
b in_loop /* branch to in_loop */
in_loop_end:
mov r3, #0 /* r3 <- 0 */
ldr r4, =array /* r4 <- array */
sum_loop:
cmp r3, #5 /* compare r3 and 5 */
bge sum_loop_end /* branch to sum_loop_end if r3 >= 5 */
add r6, r6, r4 /* add onto sum in r6 with r4 as array[i] */
add r4, r4, #1 /* r4 <- r4 + 1 */
add r3, r3, #1 /* r2 <- r2 + 1 */
b sum_loop /* branch to sum_loop */
sum_loop_end:
mov r1, r6
ldr r0, =print /* r1 <- addr_print */
bl printf /* calls printf */
pop {fp, pc}
```
preferably with a bullet to the head,
Try harder
git gud
I do have a textbook, but it doesn't go over specifics, just the general instruction set, and it's mostly computer architecture, there's one chapter on assembly
It seems to be summing the addresses instead of the values themselves
working on fixing that at the moment
Make sure you're loading the proper thing.
I believe I am, but I must be going wrong somewhere as my output is always the same thing, 676195
@meratrix have you tried going through line by line?
yeah, I've looking at the registers using gdb, it's really simple, a single line in the sum_loop
```
.data
print: .asciz "%d\n"
scan: .asciz "%d"
array: .skip 20
a: .word
.text
.global main
main:
push {fp, lr}
mov r6, #0 /* r6 <- 0 (sum) */
mov r7, #0 /* r7 <- 0 (loop counter) */
ldr r4, =array /* r4 <- &array */
in_loop:
cmp r7, #4 /* compare r3 and 4 */
bgt in_loop_end /* branch to in_loop_end if r3 >= 4 */
ldr r0, =scan /* r0 <- &scan */
ldr r1, =a /* r1 <- &a */
bl scanf /* calls scanf */
ldr r8, =a /* r8 <- &a */
str r8, [r4] /* store value of r8 into address of r4 */
add r4, r4, #4 /* r4 <- r4 + 4 */
add r7, r7, #1 /* r7 <- r7 + 1 */
b in_loop /* branch to in_loop */
in_loop_end:
mov r7, #0 /* r7 <- 0 (loop counter) */
/*ldr r4, =array*/ /* r4 <- &array */
sum_loop:
cmp r7, #4 /* compare r7 and 4 */
bgt sum_loop_end /* branch to sum_loop_end if r3 >= 4 */
lsl r5, r7, #2 /* get array offset */
ldr r9, [r4] /* r9 <- value at address r4 */
add r6, r6, r9 /* add onto sum in r6 with r5 as array[i] */
add r4, r4, #4 /* r4 <- r4 + 4 */
add r7, r7, #1 /* r7 <- r7 + 1 */
b sum_loop /* branch to sum_loop */
sum_loop_end:
mov r1, r6 /* r1 <- r6 */
ldr r0, =print /* r1 <- print */
bl printf /* calls printf */
pop {fp, pc}
```
Are you using the GNU assembler?
I am using gcc.
I actually just got a little closer, now it prints out the final number entered
hmmm,... it seems to be only storing the last number, everything else gets stored as 0
Are you using raspbian?