user2350801
user2350801

Reputation: 11

how to program an Arduino in assembly language on os x?

I am fairly new to Arduino, but not to programming. I recently bought an Arduino Uno, and despite initially learning that it could only be programmed in c,I have wanted to see if I could program it in assembly language. If anyone would be able to show me how I can on Mac osx or recommend any tutorials for learning this, it would be greatly appreciated. Also if this question is redundant,I am sorry, but please refer me to the answer that answers my question.

Upvotes: 0

Views: 4545

Answers (2)

mpflaga
mpflaga

Reputation: 2827

Several options.

  1. You can AVR GCC using avr-as.exe or with a make file.
    1. For Mac I would recommend AdaFruit's Mac Setup Guide quite through.
    2. avr-gcc-4.8_2013-03-06_mingw32.zip download of latest. You can also use 4.3.2 that is supplied with Arduino's IDE

You may be able to get the following windows to run under MAC.

  1. WINAVR w/ avr gcc website
  2. WINAVRASM tutortial

And for any OS

  1. Arduino IDE with inline assembly. (great for getting feet wet in assembly)

The later actually using the Arduino's IDE to have assembly directly along side the C++, as it is using GCC, has the significant advantage that you can continue to use the Arduino Boot loader.

You can grep(file search) through the .\arduino-1.5.5\hardware\arduino. directories searching for "asm" looking plenty of examples

Example: 1

asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz

Example: 2

__asm__ __volatile__                         \
(                                            \
    "movw  r0, %3\n\t"                       \
    "sts %0, %1\n\t"                         \
    "spm\n\t"                                \
    "clr  r1\n\t"                            \
    :                                        \
    : "i" (_SFR_MEM_ADDR(__SPM_REG)),        \
      "r" ((uint8_t)__BOOT_PAGE_FILL),       \
      "z" ((uint16_t)address),               \
      "r" ((uint16_t)data)                   \
    : "r0"                                   \
); 

Example 3:

asm volatile ( \
  "clr r26 \n\t" \
  "mul %A1, %B2 \n\t" \
  "movw %A0, r0 \n\t" \
  "mul %A1, %A2 \n\t" \
  "add %A0, r1 \n\t" \
  "adc %B0, r26 \n\t" \
  "lsr r0 \n\t" \
  "adc %A0, r26 \n\t" \
  "adc %B0, r26 \n\t" \
  "clr r1 \n\t" \
  : \
  "=&r" (intRes) \
  : \
  "d" (charIn1), \
  "d" (intIn2) \
  : \
  "r26" \
)

http://www.nongnu.org/avr-libc/user-manual/inline_asm.html

Upvotes: 4

ladislas
ladislas

Reputation: 3070

Here is a blog post that may answer your question: http://forum.arduino.cc/index.php/topic,37130.0.html

But as the RuggedCircuits says: "Final word of advice: it's really not worth it"

Hope it helps!

Upvotes: 0

Related Questions