0

I'm attempting to learn Assembly for the Arduino Uno, currently, I'm using the Arduino IDE and a .S file in which I overwrite the setup and loop functions. I want to make the Arduino receive a serial character and do something depending on what character it received. However, I can't seem to find how to call standard Arduino functions from the .S file. Specifically, I want to call the Serial.begin, Serial.read and Serial.available functions. If someone could point me in the right direction I would much appreciate it.

Edit:

I was able to call C functions from assembly (the delay function in this case) and pass it parameters. Now i've tried to do the same for "Serial.begin(9600)" with the folowing code:

.extern Serial.begin
setup:  
  ldi r22, 0b10000000 ; set 9600 as a long for the first parameter
  ldi r23, 0b00100101
  clr r24
  clr r25
  call Serial.begin ; call serial begin
...

the idea is to move 9600 in the registers r22:r25 as I understand that is where it will expect the first parameter. I am positive there is a better way to do this but thats the way I came up with. Compiling this yields the error: "undefined reference to `Serial.begin'"

if anyone could help me I would appreciate it.

ignacio murillo
  • 121
  • 1
  • 6
  • Voting to close for now... Please add more details, and try to narrow down this question. Especially, give some links about the assembly code you're talking about, as well as some of the code you tried... – Macmade Oct 30 '16 at 22:24
  • Looks as `begin` is function of some class `Serial`. Assembler is not aware of such structures, you have to give it the function itself, if it's C++, then the name of the functions is probably some Serial_begin_mangled_a_lot, in C similar. If it's virtual function, you will have to fetch it's address from `vtable` of particular object instance. Probably the best way to get idea what you want is to write it in C and check out assembly produced by compiler. And set up some listing files for mangled symbol names, or objdump the object files. – Ped7g Oct 31 '16 at 02:37
  • Anyway, I would refrain from calling such things from asm, better create C-like API gate entry for asm, with wrappers for object functions. So you will call from asm some `export "C" serial_begin_asm_gate(arg1) { Serial.begin(arg1); }` = problem with complex classes and virtual function resolved by compiler in the wrapper. – Ped7g Oct 31 '16 at 02:40

0 Answers0