CALL/de

From MCS Wiki AVR
< CALL(Difference between revisions)
Jump to: navigation, search
((**COPIED FROM ENGLISH PAGE**) =)
(Example)
 
(4 intermediate revisions by one user not shown)
Line 23: Line 23:
  
 
| valign="top" width="100%" style="width: 308px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 308px; border: 1px solid rgb(0, 0, 0);" |  
Any BASCOM variable or constant.
+
BASCOM-Variable oder Konstante.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 30: Line 30:
  
 
| valign="top" width="100%" style="width: 308px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 308px; border: 1px solid rgb(0, 0, 0);" |  
Any BASCOM variable or constant.
+
BASCOM-Variable oder Konstante.
  
 
|- style="vertical-align: top;"
 
|- style="vertical-align: top;"
Line 37: Line 37:
  
 
| valign="top" width="100%" style="width: 308px; border: 1px solid rgb(0, 0, 0);" |  
 
| valign="top" width="100%" style="width: 308px; border: 1px solid rgb(0, 0, 0);" |  
Name of the subroutine. In this case Test.
+
Name der Subroutine. In diesem Fall Test.
  
 
|}
 
|}
Line 43: Line 43:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
You can call sub routines with or without passing parameters.
+
Man kann Subroutinen mit oder ohne Parameterübergabe aufrufen.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
It is important that the SUB routine is DECLARED before you make the CALL to the subroutine. Of course the number of declared parameters must match the number of passed parameters.
+
Es ist wichtig, dass die Subroutine deklariert wird bevor sie aufgerufen wird. Natürlich muss die Anzahl der deklarierten Parameter mit der Anzahl der übergebenen Parameter übereinstimmt.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 53: Line 53:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
It is also important that when you pass constants to a SUB routine, you must DECLARE these parameters with the BYVAL argument.
+
Es ist außerdem wichtig, dass die Parameter bei Übergabe von Konstanten mit BYVAL deklariert werden.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
With the CALL statement, you can call a procedure or subroutine.
+
Mit dem CALL-Befehl kann man Prozeduren und Subroutinen aufrufen.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
For example: Call Test2
+
Zum Beispiel: Call Test2
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 67: Line 67:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
The call statement enables you to implement your own statements.
+
Der CALL-Befehl ermöglicht es, eigene Befehle zu definieren.
  
You don't have to use the CALL statement:
+
Man muss CALL nicht explizit schreiben:
  
Test2 will also call subroutine test2
+
Test2 ruft ebenfalls die Subroutine test2 auf.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 77: Line 77:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
When you don't supply the CALL statement, you must leave out the parenthesis.
+
Wenn man CALL nicht explizit schreibt dann müssen die Klammern weggelassen werden.
  
So Call Routine(x,y,z) must be written as Routine x,y,x
+
Also muss  Call Routine(x,y,z)   geschrieben werden als    Routine x,y,x
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
Unlike normal SUB programs called with the GOSUB statement, the CALL statement enables you to pass variables to a SUB routine that may be local to the SUB.
+
Im Gegensatz zu normalen Unterprogrammen die mit GOSUB aufgerufen werden erlaubt der CALL-Befehl die Übergabe von Parametern.
  
 
&nbsp;
 
&nbsp;
  
[[File:Notice.jpg|left|Notice.jpg]]By using CONFIG SUBMODE=NEW, you do not need to DECLARE each sub/function.
+
[[File:Notice.jpg|left|Notice.jpg]]Durch Benutzung von CONFIG SUBMODE=NEW braucht man nicht jede Subroutine bzw. Funktion vorher zu deklarieren.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 93: Line 93:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">See also</span> =
+
= <span class="f_Header">Siehe auch</span> =
  
 
[[DECLARE]]&nbsp;,&nbsp;[[SUB]]&nbsp;,&nbsp;[[EXIT]]&nbsp;,&nbsp;[[FUNCTION]]&nbsp;,&nbsp;[[LOCAL]]&nbsp;,&nbsp;[[CONFIG SUBMODE|CONFIG SUBMODE]]
 
[[DECLARE]]&nbsp;,&nbsp;[[SUB]]&nbsp;,&nbsp;[[EXIT]]&nbsp;,&nbsp;[[FUNCTION]]&nbsp;,&nbsp;[[LOCAL]]&nbsp;,&nbsp;[[CONFIG SUBMODE|CONFIG SUBMODE]]
Line 101: Line 101:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">Example</span> =
+
= <span class="f_Header">Beispiel</span> =
  
 
<br/><source lang="bascomavr">
 
<br/><source lang="bascomavr">
$regfile = "m48def.dat" ' specify the used micro
+
$regfile = "m48def.dat" ' Mikrocontroller
$crystal = 8000000 ' used crystal frequency
+
$crystal = 8000000 ' Taktfrequenz
$baud = 19200 ' use baud rate
+
$baud = 19200 ' Baudrate
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$swstack = 10 ' default use 10 for the SW stack
 
$swstack = 10 ' default use 10 for the SW stack
Line 114: Line 114:
 
   
 
   
 
   
 
   
Dim A As Byte , B As Byte 'dimension some variables
+
Dim A As Byte , B As Byte 'Einige Variablen dimensionieren
Declare Sub Test(b1 As Byte , Byval B2 As Byte) 'declare the SUB program
+
Declare Sub Test(b1 As Byte , Byval B2 As Byte) 'Subroutine deklarieren
A = 65 'assign a value to variable A
+
A = 65 'Der Variablen A einen Wert zuweisen
Call Test(a , 5)'call test with parameter A and constant
+
Call Test(a , 5)'Subroutine Test mit einer Variablen und einer Konstanten aufrufen
Test A , 5 'alternative call
+
Test A , 5 'alternative Aufrufmöglichkeit
Print A 'now print the new value
+
Print A 'Den neuen Wert ausgeben
 
End
 
End
 
   
 
   
Sub Test(b1 As Byte , Byval B2 As Byte) 'use the same variable names as 'the declared one
+
Sub Test(b1 As Byte , Byval B2 As Byte) 'Benutzen Sie die selben Variablennamen wie bei der Deklaration
Print B1 'print it
+
Print B1 'Ausgabe
 
Print Bcd(b2)
 
Print Bcd(b2)
B1 = 10 'reassign the variable
+
B1 = 10 'Neuzuweisung
B2 = 15 'reassign the variable
+
B2 = 15 'Neuzuweisung
 
End Sub
 
End Sub
</source><br/>[[File:Notice.jpg|left|Notice.jpg]]One important thing to notice is that you can change b2 but that the change will not be reflected to the calling program!
+
</source><br/>[[File:Notice.jpg|left|Notice.jpg]]Ein wichtiger Punkt ist, dass b2 in der Subroutine verändert werden kann aber sich diese Veränderung nicht im aufrufenden Programm auswirkt!
  
Variable A is changed however.
+
Variable A wird verändert.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
This is the difference between the BYVAL and BYREF argument in the DECLARE ration of the SUB program.
+
Das ist der Unterschied zwischen dem BYVAL und dem BYREF im Deklatationsteil der Subroutine.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
When you use BYVAL, this means that you will pass the argument by its value. A copy of the variable is made and passed to the SUB program. So the SUB program can use the value and modify it, but the change will not be reflected to the calling parameter. It would be impossible too when you pass a numeric constant for example.
+
Wenn man BYVAL benutzt bedeutet das, dass man den WERT des Arguments übergibt. Es wird eine Kopie der Variablen erzeugt und der Subroutine übergeben. Dadurch kann der Wert in der Subroutine benutzt und verändert werden aber Veränderungen beeinflussen nicht den aufrufenden Parameter. Das wäre bei Übergabe einer Konstanten ja auch unmöglich.
  
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
Line 144: Line 144:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
If you do not specify BYVAL, BYREF will be used by default and you will pass the address of the variable. So when you reassign B1 in the above example, you are actually changing parameter A.
+
Wenn BYVAL nicht angegeben wird dann wird standardmäßig BYREF verwendet und die Adresse der Variablen übergeben. Wenn im obigen Beispiel eine Neuzuweisung an B1 erfolgt dann wird tatsächlich der Parameter A verändert.
  
 
<br/>{{Languages}}
 
<br/>{{Languages}}
  
 
[[Category:BASCOM Language Reference/de]]
 
[[Category:BASCOM Language Reference/de]]

Latest revision as of 00:53, 13 March 2013

Contents

Funktion

Ruft eine Subroutine auf und führt sie aus.

 

 

Syntax

CALL Test [ (var1, var-n) ]

 

 

Remarks

Var1

BASCOM-Variable oder Konstante.

Var-n

BASCOM-Variable oder Konstante.

Test

Name der Subroutine. In diesem Fall Test.

 

Man kann Subroutinen mit oder ohne Parameterübergabe aufrufen.

 

Es ist wichtig, dass die Subroutine deklariert wird bevor sie aufgerufen wird. Natürlich muss die Anzahl der deklarierten Parameter mit der Anzahl der übergebenen Parameter übereinstimmt.

 

 

Es ist außerdem wichtig, dass die Parameter bei Übergabe von Konstanten mit BYVAL deklariert werden.

 

Mit dem CALL-Befehl kann man Prozeduren und Subroutinen aufrufen.

 

Zum Beispiel: Call Test2

 

 

Der CALL-Befehl ermöglicht es, eigene Befehle zu definieren.

Man muss CALL nicht explizit schreiben:

Test2 ruft ebenfalls die Subroutine test2 auf.

 

 

Wenn man CALL nicht explizit schreibt dann müssen die Klammern weggelassen werden.

Also muss Call Routine(x,y,z) geschrieben werden als Routine x,y,x

 

Im Gegensatz zu normalen Unterprogrammen die mit GOSUB aufgerufen werden erlaubt der CALL-Befehl die Übergabe von Parametern.

 

Notice.jpg
Durch Benutzung von CONFIG SUBMODE=NEW braucht man nicht jede Subroutine bzw. Funktion vorher zu deklarieren.

 

 

Siehe auch

DECLARE , SUB , EXIT , FUNCTION , LOCAL , CONFIG SUBMODE

 

 

Beispiel


$regfile = "m48def.dat" ' Mikrocontroller
$crystal = 8000000 ' Taktfrequenz
$baud = 19200 ' Baudrate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
 
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 
 
Dim A As Byte , B As Byte 'Einige Variablen dimensionieren
Declare Sub Test(b1 As Byte , Byval B2 As Byte) 'Subroutine deklarieren
A = 65 'Der Variablen A einen Wert zuweisen
Call Test(a , 5)'Subroutine Test mit einer Variablen und einer Konstanten aufrufen
Test A , 5 'alternative Aufrufmöglichkeit
Print A 'Den neuen Wert ausgeben
End
 
Sub Test(b1 As Byte , Byval B2 As Byte) 'Benutzen Sie die selben Variablennamen wie bei der Deklaration
Print B1 'Ausgabe
Print Bcd(b2)
B1 = 10 'Neuzuweisung
B2 = 15 'Neuzuweisung
End Sub

Notice.jpg
Ein wichtiger Punkt ist, dass b2 in der Subroutine verändert werden kann aber sich diese Veränderung nicht im aufrufenden Programm auswirkt!

Variable A wird verändert.

 

Das ist der Unterschied zwischen dem BYVAL und dem BYREF im Deklatationsteil der Subroutine.

 

Wenn man BYVAL benutzt bedeutet das, dass man den WERT des Arguments übergibt. Es wird eine Kopie der Variablen erzeugt und der Subroutine übergeben. Dadurch kann der Wert in der Subroutine benutzt und verändert werden aber Veränderungen beeinflussen nicht den aufrufenden Parameter. Das wäre bei Übergabe einer Konstanten ja auch unmöglich.

 

 

Wenn BYVAL nicht angegeben wird dann wird standardmäßig BYREF verwendet und die Adresse der Variablen übergeben. Wenn im obigen Beispiel eine Neuzuweisung an B1 erfolgt dann wird tatsächlich der Parameter A verändert.


Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language