A simple code doesn't compile

Hello. I'm a beginner, taking a class on arduino. The question might be very basic but i tried everything including browsing through threads in this forum and nothing seems to help. I'm sure the issue is something stupid but i'll appreciate any help. The assignment we were given was to build a basic program that multiplies two 4 bits numbers in assembly language. There is no use of the actual board. This is my sketch file code:

#include<Multiply.h>
byte byte1= 11;
byte byte2=13;
int Multiply(byte1,byte2);
void setup() {
Serial.begin(9600);

}
void loop() {

// put your main code here, to run repeatedly:

Serial.print(Multiply);
}

S file:

.file "Multiply.s"

.data

.text ; loads instructions into program memory

.global Multiply ; makes the entry point label visible to the caller

int x = 4;

lds r21, x; // Load 4 into counter register
cpi r21,0; // compare value in r21 to 0
breq done; // if it is 0, done. if not, go into the loop

sbrc r22, 0; // if byte 0 of the multiplier(Q)==0, skip the next
adc r18,r24; // add multiplicand(M) to the result (A)
asr r18; // shift the result (A) right
asr r22; // shift the multiplier (Q) right
ld r21,-x; // count=count-1

done:
mov r24,r22;
mov r25,r18;
ret;

h file:

extern “C” unsigned int Multiply(byte,byte);

Keeps saying: exit status 1: Error compiling for board arduino/genuino uno

Any suggestions?
thanks ahead

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don't want to be in the code tags. If your browser doesn't show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the "How to use this forum" post. Please read it.

dannypapish:
Keeps saying: exit status 1: Error compiling for board arduino/genuino uno

I'm pretty sure it says a lot more than that. The "exit status 1: Error compiling for board arduino/genuino uno" error only tells you that something went wrong. There are an almost infinite number of causes. You need to look at the full contents of the black console window at the bottom of the Arduino IDE window to see the specific error message.

Please do this:

  • When you encounter an error, you'll see a button on the right side of the orange bar "Copy error messages" in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button..
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  • Press "Ctrl + V". This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\ZIVKAB~1\AppData\Local\Temp\arduino_modified_sketch_564227\Multiply.ino: In function 'void loop()':

Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\ZIVKAB~1\AppData\Local\Temp\arduino_modified_sketch_408595\Multiply.ino: In function 'void loop()':

Multiply:16:39: error: expected ')' before ';' token

     Serial.print(Multiply(byte1,byte2);

                                       ^

Multiple libraries were found for "Multiply.h"
 Used: C:\Users\Ziv
exit status 1
expected ')' before ';' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

changed the first line to: #include <C:\Users\Ziv Kabeda\Documents\Arduino\libraries\Multiply\Multiply.h>

and now i get this:

Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\ZIVKAB~1\AppData\Local\Temp\ccHbGTFe.ltrans0.ltrans.o: In function `loop':

C:\Users\ZIVKAB~1\AppData\Local\Temp\arduino_modified_sketch_606758/Multiply.ino:16: undefined reference to `Multiply'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

OK, lots of problems here.

The first thing you need to do is turn on compiler warnings. The compiler will print lots of helpful hints about potential problems in your code to the console, but only if you let it.

So set File > Preferences > Compiler warnings to "All".

Note that warnings are not errors. Don't freak out the moment you see a compiler warning. Just read it and try to understand what the compiler is telling you. You should always try to write your own code so that it doesn't produce warnings, but other developers won't have been so kind and so you will find that some libraries have warnings. Often these are safe to ignore (though annoying).

dannypapish:

byte byte1= 11;

byte byte2=13;

These variables don't have any purpose in your current code. You seem to think that you are passing those to the Multiply function just because they have the same name as the function parameters, but you're not. You really need to take some time to learn the basics of C++ before you start diving into writing assembly and libraries. I recommend this tutorial:
http://www.cplusplus.com/doc/tutorial/
Not all of it applies to embedded systems, so you will need to get a feel for which parts to skip over. You also don't need to go through the whole thing all at once. Just work through until you hit the parts that aren't immediately useful for your needs, then you can come back to those later.

dannypapish:

int Multiply(byte1,byte2);

This is a malformed function prototype. You need to specify the parameter types in function prototypes:

int Multiply(byte byte1, byte byte2);

And note that you could have used any names you like for the parameters (or none at all, as you did in Multiply.h):

int Multiply(byte foo, byte bar);

they have no relation to the variables of that name you declared above.

But you already have a prototype for this function in Multiply.h:

Worse, they have different return types!

So get rid of that unnecessary and wrong prototype in the sketch file.

I guess you think you are passing the return value of Multiply to Serial.print(), but you didn't use the right syntax for a function call to Multiply. What you're actually doing here is passing the function pointer to Serial.print(), which is not supported. The correct syntax looks like this:

Serial.print(Multiply(byte1, byte2);

Note that this is passing the value of the variables byte1 and byte2 to the Multiply function:

byte byte1= 11;
byte byte2=13;

This has nothing to do with the parameter names byte1 and byte2 that you used in the declaration of the function.

dannypapish:
S file:

 .file "Multiply.s"

OK, this one is tricky. Even though Windows is filename case insensitive, the Arduino IDE is not. The extension of assembly files must be .S, not .s.

dannypapish:

int x = 4;

lds r21, x; // Load 4 into counter register

What's going on here?

dannypapish:

lds r21, x; // Load 4 into counter register

cpi r21,0; // compare value in r21 to 0
breq done; // if it is 0, done. if not, go into the loop

sbrc r22, 0; // if byte 0 of the multiplier(Q)==0, skip the next
adc r18,r24; // add multiplicand(M) to the result (A)
asr r18; // shift the result (A) right
asr r22; // shift the multiplier (Q) right
ld r21,-x; // count=count-1

done:
mov r24,r22;
mov r25,r18;
ret;

You forgot that you were trying to make a Multiply function. You do it like this in assembly:

Multiply:
  lds r21, 4; // Load 4 into counter register
  cpi r21,0; // compare value in r21 to 0
  breq done; // if it is 0, done. if not, go into the loop
  
  sbrc r22, 0; // if byte 0 of the multiplier(Q)==0, skip the next
  adc r18,r24; // add multiplicand(M) to the result (A)
  asr r18;     // shift the result (A) right
  asr r22;     // shift the multiplier (Q) right
  ld r21,-x; // count=count-1
  
  done:
  mov r24,r22;
  mov r25,r18;
  ret;

dannypapish:
changed the first line to: #include <C:\Users\Ziv Kabeda\Documents\Arduino\libraries\Multiply\Multiply.h>

That's a bad idea. If you only have header files in C:\Users\Ziv Kabeda\Documents\Arduino\libraries\Multiply, it will work, but it won't work if you have any source files in that folder. My recommendation is to forget about writing libraries for now. You are having way too much trouble with the most basic fundamentals of programming to even consider adding that extra complexity. Just add all the files to your sketch folder. You can do that in the Arduino IDE by clicking the downward pointing triangle button on the right side of the tab bar, then "New Tab". Note that each tab in the sketch is a separate file. If you don't give the file a recognized extension (.h, .S, .cpp, .c), then it will automatically be given the .ino extension of Arduino sketch files (which are compiled as C++).

In order to #include files from the sketch, you need to use the #include "foo.h" syntax, which causes the local folder to be searched before looking in the library folders. The #include <foo.h> syntax will only search the library folders, so files in the sketch folder won't be found.

In this case, you don't even need the .h file, you can just put the Multiply function prototype in your sketch. That's not to say you shouldn't even use .h files, but for an absolute beginner like you it's just an unnecessary complication. Start as simple as possible, then add additional complexity once you've mastered the basics.

dannypapish:

Multiple libraries were found for "Multiply.h"

Used: C:\Users\Ziv

FYI, the part of the "Used" library being truncated after Ziv is a bug in Arduino IDE 1.8.10, which does this where there is a space in the path. You may be able to guess what the rest of the path would be, or if it's causing you problems you can use Arduino IDE 1.8.9 instead.