Assembly using "Atmel" :
1- Write a program that counts from 0 to 255 and show the result on PORTD (shown on 8 LEDs).
2- Write a program that adds two numbers and show their sum on PORTD.
1.
int LPins[] = {2,3,4,5,6,7,8,9};
void setup()
{
for(int i = 0; i < 8; i++)
{
pinMode(LPins[i],OUTPUT);
}
}
void loop()
{
for (int i=0; i<256; i++)
{
showBinNumber(i);
delay(256-i);
}
}
void showBinNumber(int num) {
for (int i=0; i<8; i++) {
if (num%2)
digitalWrite(LPins[i], HIGH);
else
digitalWrite(LPins[i], LOW);
num/=2;
}
}
2.
# Number 1
LDI R16 0x…
LDI R17 0x…
LDI R18 0x…
LDI R19 0x…
# Number 2
LDI R20 0x…
LDI R21 0x…
LDI R22 0x…
LDI R23 0x…
# Add LSB of 1 and 2, result will be in R20
ADD R20,R16
# Add remaining bytes using the add-with-carry operation
ADC R21,R17
ADC R22,R18
ADC R23,R19 # MSB
Get Answers For Free
Most questions answered within 1 hours.