Modifications

Sauter à la navigation Sauter à la recherche
272 octets ajoutés ,  19 avril 2015 à 09:47
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{MicroPython-Hack-Prepare-NAV}}
 
{{MicroPython-Hack-Prepare-NAV}}
  −
{{traduction}}
      
== introduction ==
 
== introduction ==
Ligne 40 : Ligne 38 :     
== Accepter des arguments ==
 
== Accepter des arguments ==
 +
Une fonction assembleur Inline peut accepter jusqu'à 3 arguments. Si ils sont utilisés, ces arguments doivent être nommés {{fname|r0}}, {{fname|r1}} et {{fname|r2}} pour refléter les registres et les conventions d'appel.
   −
Inline assembler functions can accept up to 3 arguments. If they are used, they must be named {{fname|r0}}, {{fname|r1}} et {{fname|r2}} to reflect the registers and the calling conventions.
+
Voici une fonction qui additionne ces arguments:
 
  −
Here is a function that adds its arguments:
      
  <nowiki>@micropython.asm_thumb
 
  <nowiki>@micropython.asm_thumb
Ligne 49 : Ligne 46 :  
     add(r0, r0, r1)</nowiki>
 
     add(r0, r0, r1)</nowiki>
   −
This performs the computation {{fname|1=r0 = r0 + r1}}. Since the result is put in {{fname|r0}}, that is what is returned. Try {{fname|asm_add(1, 2)}}, it should return 3.
+
Cette fonction exécute le calcul {{fname|1=r0 = r0 + r1}}. Etant donné que le résultat est placé dans le registre {{fname|r0}}, ce sera donc la valeur qui sera retournée.  
 +
 
 +
Essayez la commande {{fname|asm_add(1, 2)}} qui devrait retourner la valeur 3.
    
== Les boucles ==
 
== Les boucles ==
We can assign labels with {{fname|label(my_label)}}, and branch to them using {{fname|b(my_label)}}, or a conditional branch like {{fname|bgt(my_label)}}.
+
Nous pouvons assigner un libellé (''label'' en anglais) a l'aide de {{fname|label(mon_label)}}, et faire sauter l'exécution du code vers l'étiquette (''to branch'' en anglais) en utilisant {{fname|b(mon_label)}}, ou un branchement conditionnel tel que {{fname|bgt(mon_label)}}.
   −
The following example flashes the green LED. It flashes it {{fname|r0}} times.
+
L'example de code suivant fait clignoter la LED vertes. La LED clignotera {{fname|r0}} fois.
    
  <nowiki>@micropython.asm_thumb
 
  <nowiki>@micropython.asm_thumb
 
def flash_led(r0):
 
def flash_led(r0):
     # get the GPIOA address in r1
+
     # placer l'adresse GPIOA dans r1
 
     movwt(r1, stm.GPIOA)
 
     movwt(r1, stm.GPIOA)
   −
     # get the bit mask for PA14 (the pin LED #2 is on)
+
     # obtenir un masque de bits pour PA14 (broche de la LED #2)
 
     movw(r2, 1 << 14)
 
     movw(r2, 1 << 14)
   Ligne 68 : Ligne 67 :  
     label(loop1)
 
     label(loop1)
   −
     # turn LED on
+
     # allumer la LED
 
     strh(r2, [r1, stm.GPIO_BSRRL])
 
     strh(r2, [r1, stm.GPIO_BSRRL])
   −
     # delay for a bit
+
     # attendre un moment
 
     movwt(r4, 5599900)
 
     movwt(r4, 5599900)
 
     label(delay_on)
 
     label(delay_on)
Ligne 78 : Ligne 77 :  
     bgt(delay_on)
 
     bgt(delay_on)
   −
     # turn LED off
+
     # éteindre la LED
 
     strh(r2, [r1, stm.GPIO_BSRRH])
 
     strh(r2, [r1, stm.GPIO_BSRRH])
   −
     # delay for a bit
+
     # Attendre un peu
 
     movwt(r4, 5599900)
 
     movwt(r4, 5599900)
 
     label(delay_off)
 
     label(delay_off)
Ligne 88 : Ligne 87 :  
     bgt(delay_off)
 
     bgt(delay_off)
   −
     # loop r0 times
+
     # boucler r0 fois
 
     sub(r0, r0, 1)
 
     sub(r0, r0, 1)
 
     label(loop_entry)
 
     label(loop_entry)
29 917

modifications

Menu de navigation