Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Michael Rowan
2,357 PointsTrouble with Geany
Hi guys, I have just started doing some Geany assembly code, I am finding one exercise really frustrating.
Given an integer n, if n > 0 compute the sum of all integers from 1 to n, inclusively.
If n < 0, compute the sum of all integers from -1 down to n, inclu-sively.
If n = 0, the result is 0.
That is the exercise and here is my code;
asect 0x00
br start
asect 0x02
n: dc 4
a: dc 3 b: dc 2 c: dc 1
asect 0x20
res: ds 1 start:
ldi r0, n
ld r0, r0
ldi r1, 0
ldi r2, a
ld r2, r2
ldi r3, b
ld r3, r3
if
cmp r0, r1
is ge
add r0, r2
add r2, r3
ldi r2, c
ld r2, r2
add r3, r2
else
cmp r0, r1
is le
sub r2, r3
ldi r2, c
ld r2, r2
sub r3, r2
fi
ldi r0,res
st r0, r2
halt
end
Not sure if this is very clear to read, wasn't sure how to attach a picture, but if anyone is able to give me some help, it would be really appreciated. Thanks!!