Help for Assembly Newb

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I am trying learn assembly.

 

Could someone please explain the loop below and when/where/how many times it loops?

 

ldi R16, 40                
outer_loop:
ldi R24, low($4000)    
ldi R25, high($4000)    
inner_loop:
sbiw R24, 1             
brne inner_loop       
dec R16                    
brne outer_loop

 

Thanks in advance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It loads  hex  4000 into the pair...decimal 16384

it counts it down one by one until zero

 

Then it repeats this process 40 times.

 

You have to figure out the details yourself

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you. The didn't realize the hex.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

If you make a build-able program then you can run it in the simulator and you can see what is going on by running it in single step.

 

Of course you will have to use smaller numbers as the simulator is very slow other wise you will be a very old person by the same the loop end.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting inconsistency (hobgoblin of little minds?):

 

The ldi R16 is in decimal.

ldi R24 and ldi R25 is in hex.

sbiw R24 is in decimal again.

[dec r16 doesn't care].

 

S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
you will have to use smaller numbers as the simulator is very slow

Actually, you could manually adjust the counts in the simulator - so you don't have to change the source code ....

 

Not a big deal in this case, but a useful debugging/testing technique in general ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting inconsistency (hobgoblin of little minds?):

 

The ldi R16 is in decimal.

ldi R24 and ldi R25 is in hex.

sbiw R24 is in decimal again.

[dec r16 doesn't care].

 

Perhaps the original author worked for NASA...

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

 

Perhaps the original author worked for NASA...

or perhaps the ESA!

 

Thanks for the laugh!

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"