Simple Assembler Question

Thread Starter

TwoPlusTwo

Joined Oct 14, 2010
51
Hi,

I'm trying to learn Assembler programming and I'm supposed to write a program that does this:

- stores 5 numbers
- reads those numbers and calculates the sum
- writes the sum on the diodes of my practice board (STK500)

Here's what I got:

.nolist
.include "m32def.inc"
.list

.def sum=R21
clr sum
out ddrb, sum

ldi R16, 0x2c
ldi R17, 0x0f
ldi R18, 0x49
ldi R19, 0x37
ldi R20, 0x19

add sum, R16
add sum, R17
add sum, R18
add sum, R19
add sum, R20
out PortB, sum

But nothing happens. Do I need some sort of ending to the program?
 

hgmjr

Joined Jan 28, 2005
9,027
You have not set your PORTB direction as outputs. You set them to inputs. Fix this and you should get your LEDs to light. I am assuming that you put current limiting resistors in series with your LEDs.

You will also need to put what is commonly referred to as an "infinite loop" at the end of your program or it will go out into the weeds.


hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
Greetings twoplustwo,

I have moved your thread on the AVR code assistance request over to the homework section. Let me know if this is not a class assignment and I will be happy to move it back to the programming forum.

By putting the post in the homework section the intent is to signal to our members that help is to be provided contingent on the your effort. You have provided the requisite first attempt and encountered your first snag. I have provided a couple of comments in the form of suggestions without being specific on how to accomplish these suggestions. The idea is to lead you to the answer rather than blurt out the answer. By leading you to the answer in gradual steps you will have the opportunity to dig for the answer. It is important that we take this approach since you will not be able to consult AAC in the middle of a test so you can develop the skills needed to work out the answer on your own in an examination environment.

Let us know if you still have questions. We encourage you to seek out the solution on your own as much as possible so that the knowledge will be yours rather than being spoon-fed to you.

Good Luck,
hgmjr
 

Thread Starter

TwoPlusTwo

Joined Oct 14, 2010
51
Thanks for the tip! So here's what I have now. Am I getting closer?

.nolist
.include "m32def.inc"
.list

.def sum=R21
ldi sum, 0xff
out ddrb, sum
clr sum

ldi R16, 0x2c
ldi R17, 0x0f
ldi R18, 0x49
ldi R19, 0x37
ldi R20, 0x19

add sum, R16
add sum, R17
add sum, R18
add sum, R19
add sum, R20
loop:
out PortB, sum
rjmp loop
 

hgmjr

Joined Jan 28, 2005
9,027
That looks much better. Did it work in your breadboard?

By the way, You don't need to place the out PortB, sum inside the loop.

hgmjr
 
Top