Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:multiasm:piot:chapter_4_9 [2026/01/19 13:57] marcinen:multiasm:piot:chapter_4_9 [2026/02/27 01:13] (current) – [Examples] jtokarz
Line 1: Line 1:
 ====== 3 Levels of Programming: C++, Libraries, Assembler ====== ====== 3 Levels of Programming: C++, Libraries, Assembler ======
  
-Programming AVR microcontrollers can be divided into three levels: C++, libraries, and assembler. Each of these levels offers distinct benefits and is utilized according to the project's specific requirements.+Programming AVR microcontrollers can be divided into three levels: C++, libraries, and assembler. Each of these levels offers distinct benefits and is utilised according to the project's specific requirements.
  
   * **C++** is a high-level language that allows programmers to write code in a more abstract and understandable way. Using C++ for AVR enables advanced features such as object-oriented programming, inheritance, and polymorphism. This makes the code more modular and easier to maintain. Compilers like AVR-GCC convert C++ code into machine code that the microcontroller can execute.   * **C++** is a high-level language that allows programmers to write code in a more abstract and understandable way. Using C++ for AVR enables advanced features such as object-oriented programming, inheritance, and polymorphism. This makes the code more modular and easier to maintain. Compilers like AVR-GCC convert C++ code into machine code that the microcontroller can execute.
   * **Libraries** are sets of predefined functions and procedures that facilitate programming AVR microcontrollers. An example is the AVR Libc library, which provides functions for I/O, memory management, and mathematical operations. Using libraries enables rapid application development without writing code from scratch. Libraries are particularly useful in projects that require frequent use of standard functions.   * **Libraries** are sets of predefined functions and procedures that facilitate programming AVR microcontrollers. An example is the AVR Libc library, which provides functions for I/O, memory management, and mathematical operations. Using libraries enables rapid application development without writing code from scratch. Libraries are particularly useful in projects that require frequent use of standard functions.
-  * **Assembler** is a low-level language that allows direct programming of the AVR microcontroller. Writing code in assembler gives full control over the hardware and allows for performance optimization. However, programming in assembler requires a deep understanding of the microcontroller's architecture and is more complex than programming in C++. An assembler is often used in critical applications where every clock cycle counts. +  * **Assembler** is a low-level language that allows direct programming of the AVR microcontroller. Writing code in assembler gives full control over the hardware and allows for performance optimisation. However, programming in assembler requires a deep understanding of the microcontroller's architecture and is more complex than programming in C++. An assembler is often used in critical applications where every clock cycle counts.
- +
-The choice of programming level depends on the project's specifics. C++ is ideal for creating complex applications, libraries facilitate rapid prototyping, and assembler provides maximum control and performance. Each of these levels has its place in AVR microcontroller programming.''+
  
 +The choice of programming level depends on the project's specifics. C++ is ideal for creating complex applications, libraries facilitate rapid prototyping, and assembler provides maximum control and performance. Each of these levels has its place in AVR microcontroller programming.
  
  
Line 16: Line 15:
  
 **Blink inbuilt LED on pin 13 (port PB5) using assembly** **Blink inbuilt LED on pin 13 (port PB5) using assembly**
 +<code c>
   void setup() {   void setup() {
-    // Set PB5 (pin 13) as output  // if DDRB (Data Direction Register B) = 1, PORTB is output +    // Set PB5 (pin 13) as output   
 +    // if DDRB (Data Direction Register B) = 1, PORTB is output 
     asm volatile("sbi 0x04, 5");   // DDRB |= (1<<5)     asm volatile("sbi 0x04, 5");   // DDRB |= (1<<5)
   }   }
Line 27: Line 27:
     delay(500);     delay(500);
   }   }
-  +</code>
 For Arduino Uno (ATmega328P):     For Arduino Uno (ATmega328P):    
   * DDRB has address 0x04   * DDRB has address 0x04
Line 36: Line 36:
  
 **Add two numbers using AVR registers** **Add two numbers using AVR registers**
 +<code c>
   void setup() {   void setup() {
     Serial.begin(9600);     Serial.begin(9600);
Line 44: Line 45:
       "add r24, r25\n"  // r24 = a + b       "add r24, r25\n"  // r24 = a + b
       "mov %0, r24\n"   // result = r24       "mov %0, r24\n"   // result = r24
-      : "=r"(result) +      : "=r"(result)    // agrument %0 
-      : "r"(a), "r"(b) +      : "r"(a), "r"(b)  // arguments %1, %2 
-      : "r24", "r25", "cc" +      : "r24", "r25", "cc" // preserve the content of r24 and r25
     );     );
     Serial.println(result);     Serial.println(result);
   }   }
   void loop() {}   void loop() {}
 +</code>
 ---- ----
  
 **Read digital input (PD2, bit 2 on PORTD)** **Read digital input (PD2, bit 2 on PORTD)**
 +<code c>
   void setup() {   void setup() {
     Serial.begin(9600);     Serial.begin(9600);
Line 68: Line 70:
     delay(200);     delay(200);
   }   }
-  +</code> 
en/multiasm/piot/chapter_4_9.1768823862.txt.gz · Last modified: by marcin
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0