Arduino ATMega2560 use Assembler instead of C
I have an Arduino board ATmega2560 and I would like to code assembler on it. I made some code in C for showing the temperature on an LCD16x2 using a temperature sensor. But I'd like to code the same functionality but in Assembler this time. I'm pretty new to assembler and I'd like to know how should I start doing it and maybe there's someone who can help me converting my current code into Assembler? I couldn't find that many tutorials for this board.
My C code is the following :
#include <LiquidCrystal.h>
int tim = 50; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
int thermistorPin = 0; // thermistor connected to analog pin 3
void setup()
{
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
}
void loop()
{
float a = analogRead(thermistorPin);
//the calculating formula of temperature
float resistor = (1023.0*10000)/a-10000;
float tempC = (3435.0/(log(resistor/10000)+(3435.0/(273.15+25)))) - 200.00;
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print(" THIS IS A TEST ");// Print a message of "Temp: "to the LCD.
lcd.setCursor(0, 1); // set the cursor to column 0, line 0
lcd.print(" Temp: ");// Print a message of "Temp: "to the LCD.
lcd.print(tempC);// Print a centigrade temperature to the LCD.
lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.
delay(500);
}
assembly arduino avr
add a comment |
I have an Arduino board ATmega2560 and I would like to code assembler on it. I made some code in C for showing the temperature on an LCD16x2 using a temperature sensor. But I'd like to code the same functionality but in Assembler this time. I'm pretty new to assembler and I'd like to know how should I start doing it and maybe there's someone who can help me converting my current code into Assembler? I couldn't find that many tutorials for this board.
My C code is the following :
#include <LiquidCrystal.h>
int tim = 50; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
int thermistorPin = 0; // thermistor connected to analog pin 3
void setup()
{
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
}
void loop()
{
float a = analogRead(thermistorPin);
//the calculating formula of temperature
float resistor = (1023.0*10000)/a-10000;
float tempC = (3435.0/(log(resistor/10000)+(3435.0/(273.15+25)))) - 200.00;
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print(" THIS IS A TEST ");// Print a message of "Temp: "to the LCD.
lcd.setCursor(0, 1); // set the cursor to column 0, line 0
lcd.print(" Temp: ");// Print a message of "Temp: "to the LCD.
lcd.print(tempC);// Print a centigrade temperature to the LCD.
lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.
delay(500);
}
assembly arduino avr
4
that is a major effort, the floating point alone. set your goals a little more realistic for first efforts with assembly language, and probably start with an instruction set simulator. try blinking an led. and yes it is very doable, you can generate binaries from assembly language and you can maybe use the arduino tools but certainly there are others or not hard to make your own to program the board with your program.
– old_timer
Nov 28 '18 at 22:17
I think a well known instruction set simulator is simavr. I think my simple asm programs for the arduino/avr are like 20 lines of code to blink an led. need to enable the port for output and then set or clear the bit, most of the code is counting to a big enough number between blinks that you can see the led changing.
– old_timer
Nov 28 '18 at 22:20
If you understand binary numbers, you could use fixed-point arithmetic in assembly as a way to learn some asm. Or maybe write fixed-point code in C and look at compiler output as a starting point to see how it implemented things. AVR doesn't have an FPU, sofloat
operations will compile into function calls to software floating point.
– Peter Cordes
Nov 28 '18 at 22:23
add a comment |
I have an Arduino board ATmega2560 and I would like to code assembler on it. I made some code in C for showing the temperature on an LCD16x2 using a temperature sensor. But I'd like to code the same functionality but in Assembler this time. I'm pretty new to assembler and I'd like to know how should I start doing it and maybe there's someone who can help me converting my current code into Assembler? I couldn't find that many tutorials for this board.
My C code is the following :
#include <LiquidCrystal.h>
int tim = 50; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
int thermistorPin = 0; // thermistor connected to analog pin 3
void setup()
{
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
}
void loop()
{
float a = analogRead(thermistorPin);
//the calculating formula of temperature
float resistor = (1023.0*10000)/a-10000;
float tempC = (3435.0/(log(resistor/10000)+(3435.0/(273.15+25)))) - 200.00;
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print(" THIS IS A TEST ");// Print a message of "Temp: "to the LCD.
lcd.setCursor(0, 1); // set the cursor to column 0, line 0
lcd.print(" Temp: ");// Print a message of "Temp: "to the LCD.
lcd.print(tempC);// Print a centigrade temperature to the LCD.
lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.
delay(500);
}
assembly arduino avr
I have an Arduino board ATmega2560 and I would like to code assembler on it. I made some code in C for showing the temperature on an LCD16x2 using a temperature sensor. But I'd like to code the same functionality but in Assembler this time. I'm pretty new to assembler and I'd like to know how should I start doing it and maybe there's someone who can help me converting my current code into Assembler? I couldn't find that many tutorials for this board.
My C code is the following :
#include <LiquidCrystal.h>
int tim = 50; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
int thermistorPin = 0; // thermistor connected to analog pin 3
void setup()
{
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner
}
void loop()
{
float a = analogRead(thermistorPin);
//the calculating formula of temperature
float resistor = (1023.0*10000)/a-10000;
float tempC = (3435.0/(log(resistor/10000)+(3435.0/(273.15+25)))) - 200.00;
lcd.setCursor(0, 0); // set the cursor to column 0, line 0
lcd.print(" THIS IS A TEST ");// Print a message of "Temp: "to the LCD.
lcd.setCursor(0, 1); // set the cursor to column 0, line 0
lcd.print(" Temp: ");// Print a message of "Temp: "to the LCD.
lcd.print(tempC);// Print a centigrade temperature to the LCD.
lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.
delay(500);
}
assembly arduino avr
assembly arduino avr
asked Nov 28 '18 at 22:12
Eduard CosteaEduard Costea
61
61
4
that is a major effort, the floating point alone. set your goals a little more realistic for first efforts with assembly language, and probably start with an instruction set simulator. try blinking an led. and yes it is very doable, you can generate binaries from assembly language and you can maybe use the arduino tools but certainly there are others or not hard to make your own to program the board with your program.
– old_timer
Nov 28 '18 at 22:17
I think a well known instruction set simulator is simavr. I think my simple asm programs for the arduino/avr are like 20 lines of code to blink an led. need to enable the port for output and then set or clear the bit, most of the code is counting to a big enough number between blinks that you can see the led changing.
– old_timer
Nov 28 '18 at 22:20
If you understand binary numbers, you could use fixed-point arithmetic in assembly as a way to learn some asm. Or maybe write fixed-point code in C and look at compiler output as a starting point to see how it implemented things. AVR doesn't have an FPU, sofloat
operations will compile into function calls to software floating point.
– Peter Cordes
Nov 28 '18 at 22:23
add a comment |
4
that is a major effort, the floating point alone. set your goals a little more realistic for first efforts with assembly language, and probably start with an instruction set simulator. try blinking an led. and yes it is very doable, you can generate binaries from assembly language and you can maybe use the arduino tools but certainly there are others or not hard to make your own to program the board with your program.
– old_timer
Nov 28 '18 at 22:17
I think a well known instruction set simulator is simavr. I think my simple asm programs for the arduino/avr are like 20 lines of code to blink an led. need to enable the port for output and then set or clear the bit, most of the code is counting to a big enough number between blinks that you can see the led changing.
– old_timer
Nov 28 '18 at 22:20
If you understand binary numbers, you could use fixed-point arithmetic in assembly as a way to learn some asm. Or maybe write fixed-point code in C and look at compiler output as a starting point to see how it implemented things. AVR doesn't have an FPU, sofloat
operations will compile into function calls to software floating point.
– Peter Cordes
Nov 28 '18 at 22:23
4
4
that is a major effort, the floating point alone. set your goals a little more realistic for first efforts with assembly language, and probably start with an instruction set simulator. try blinking an led. and yes it is very doable, you can generate binaries from assembly language and you can maybe use the arduino tools but certainly there are others or not hard to make your own to program the board with your program.
– old_timer
Nov 28 '18 at 22:17
that is a major effort, the floating point alone. set your goals a little more realistic for first efforts with assembly language, and probably start with an instruction set simulator. try blinking an led. and yes it is very doable, you can generate binaries from assembly language and you can maybe use the arduino tools but certainly there are others or not hard to make your own to program the board with your program.
– old_timer
Nov 28 '18 at 22:17
I think a well known instruction set simulator is simavr. I think my simple asm programs for the arduino/avr are like 20 lines of code to blink an led. need to enable the port for output and then set or clear the bit, most of the code is counting to a big enough number between blinks that you can see the led changing.
– old_timer
Nov 28 '18 at 22:20
I think a well known instruction set simulator is simavr. I think my simple asm programs for the arduino/avr are like 20 lines of code to blink an led. need to enable the port for output and then set or clear the bit, most of the code is counting to a big enough number between blinks that you can see the led changing.
– old_timer
Nov 28 '18 at 22:20
If you understand binary numbers, you could use fixed-point arithmetic in assembly as a way to learn some asm. Or maybe write fixed-point code in C and look at compiler output as a starting point to see how it implemented things. AVR doesn't have an FPU, so
float
operations will compile into function calls to software floating point.– Peter Cordes
Nov 28 '18 at 22:23
If you understand binary numbers, you could use fixed-point arithmetic in assembly as a way to learn some asm. Or maybe write fixed-point code in C and look at compiler output as a starting point to see how it implemented things. AVR doesn't have an FPU, so
float
operations will compile into function calls to software floating point.– Peter Cordes
Nov 28 '18 at 22:23
add a comment |
0
active
oldest
votes
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528897%2farduino-atmega2560-use-assembler-instead-of-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528897%2farduino-atmega2560-use-assembler-instead-of-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
that is a major effort, the floating point alone. set your goals a little more realistic for first efforts with assembly language, and probably start with an instruction set simulator. try blinking an led. and yes it is very doable, you can generate binaries from assembly language and you can maybe use the arduino tools but certainly there are others or not hard to make your own to program the board with your program.
– old_timer
Nov 28 '18 at 22:17
I think a well known instruction set simulator is simavr. I think my simple asm programs for the arduino/avr are like 20 lines of code to blink an led. need to enable the port for output and then set or clear the bit, most of the code is counting to a big enough number between blinks that you can see the led changing.
– old_timer
Nov 28 '18 at 22:20
If you understand binary numbers, you could use fixed-point arithmetic in assembly as a way to learn some asm. Or maybe write fixed-point code in C and look at compiler output as a starting point to see how it implemented things. AVR doesn't have an FPU, so
float
operations will compile into function calls to software floating point.– Peter Cordes
Nov 28 '18 at 22:23