cvs commit: de-docproj/books/developers-handbook/x86 chapter.sgml

From: Aron Schlesinger <as(at)doc.bsdgroup.de>
Date: Thu, 23 Aug 2007 15:49:53 GMT

as 2007-08-23 15:49:53 UTC

  FreeBSD ports repository

  Modified files:
    books/developers-handbook/x86 chapter.sgml
  Log:
  Kapitel 12.9 uebersetzt von Fabian Ruch.
  3 kleinigkeiten gefixt:
  - s/&f/f&/
  - s/&umml;/&uuml;/
  - s/<funtion>/<function>/
  
  Revision Changes Path
  1.7 +143 -166 de-docproj/books/developers-handbook/x86/chapter.sgml
  
  Index: chapter.sgml
  ===================================================================
  RCS file: /home/cvs/de-docproj/books/developers-handbook/x86/chapter.sgml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -I$FreeBSDde.*$ -r1.6 -r1.7
  --- chapter.sgml 13 Aug 2007 13:47:22 -0000 1.6
  +++ chapter.sgml 23 Aug 2007 15:49:53 -0000 1.7
  @@ -1453,76 +1453,67 @@
   
   </sect1>
   
  -<sect1 id="x86-command-line"><title>Command Line Arguments</title>
  +<sect1 id="x86-command-line">
  + <title>Kommandozeilenparameter</title>
   
  -<para>
  -Our <application>hex</application> program will be more useful if it can
  -read the names of an input and output file from its command
  -line, i.e., if it can process the command line arguments.
  -But... Where are they?
  -</para>
  -
  -<para>
  -Before a &unix; system starts a program, it <function role="opcode">push</function>es some
  -data on the stack, then jumps at the <varname>_start</varname>
  -label of the program. Yes, I said jumps, not calls. That means the
  -data can be accessed by reading <varname>[esp+offset]</varname>,
  -or by simply <function role="opcode">pop</function>ping it.
  -</para>
  -
  -<para>
  -The value at the top of the stack contains the number of
  -command line arguments. It is traditionally called
  -<varname>argc</varname>, for "argument count."
  -</para>
  -
  -<para>
  -Command line arguments follow next, all <varname>argc</varname> of them.
  -These are typically referred to as <varname>argv</varname>, for
  -"argument value(s)." That is, we get <varname>argv[0]</varname>,
  -<varname>argv[1]</varname>, <varname>...</varname>,
  -<varname>argv[argc-1]</varname>. These are not the actual
  -arguments, but pointers to arguments, i.e., memory addresses of
  -the actual arguments. The arguments themselves are
  -NUL-terminated character strings.
  -</para>
  -
  -<para>
  -The <varname>argv</varname> list is followed by a NULL pointer,
  -which is simply a <constant>0</constant>. There is more, but this is
  -enough for our purposes right now.
  -</para>
  -
  -<note>
  -<para>
  -If you have come from the <acronym>&ms-dos;</acronym> programming
  -environment, the main difference is that each argument is in
  -a separate string. The second difference is that there is no
  -practical limit on how many arguments there can be.
  -</para>
  -</note>
  + <para>Unser <application>hex</application>-Programm wird
  + n&uuml;tzlicher, wenn es die Dateinamen der Ein- und Ausgabedatei
  + &uuml;ber die Kommandozeile einlesen kann, d.h., wenn es
  + Kommandozeilenparameter verarbeiten kann. Aber... Wo sind
  + die?</para>
  +
  + <para>Bevor ein &unix;-System ein Programm ausf&uuml;hrt, legt es
  + einige Daten auf dem Stack ab (<function
  + role="opcode">push</function>) und springt dann an das
  + <varname>_start</varname>-Label des Programms. Ja, ich sagte
  + springen, nicht aufrufen. Das bedeutet, dass auf die Daten
  + zugegriffen werden kann, indem <varname>[esp+offset]</varname>
  + ausgelesen wird oder die Daten einfach vom Stack genommen werden
  + (<function role="opcode">pop</function>).</para>
  +
  + <para>Der Wert ganz oben auf dem Stack enth&auml;lt die Zahl der
  + Kommandozeilenparameter. Er wird traditionell
  + <varname>argc</varname> wie "argument count" genannt.</para>
  +
  + <para>Die Kommandozeilenparameter folgen einander, alle
  + <varname>argc</varname>. Von diesen wird &uuml;blicherweise als
  + <varname>argv</varname> wie "argument value(s)" gesprochen. So
  + erhalten wir <varname>argv[0]</varname>, <varname>argv[1]</varname>,
  + <varname>...</varname> und <varname>argv[argc-1]</varname>. Dies
  + sind nicht die eigentlichen Parameter, sondern Zeiger (Pointer) auf
  + diese, d.h., Speicheradressen der tats&auml;chlichen Parameter. Die
  + Parameter selbst sind durch NULL beendete Zeichenketten.</para>
  +
  + <para>Der <varname>argv</varname>-Liste folgt ein NULL-Zeiger, was
  + einfach eine <constant>0</constant> ist. Es gibt noch mehr, aber
  + dies ist erst einmal genug f&uuml;r unsere Zwecke.</para>
  +
  + <note>
  + <para>Falls Sie von der
  + <acronym>&ms-dos;</acronym>-Programmierumgebung kommen, ist der
  + gr&ouml;&szlig;te Unterschied die Tatsache, dass jeder Parameter
  + eine separate Zeichenkette ist. Der zweite Unterschied ist, dass
  + es praktisch keine Grenze gibt, wie viele Parameter vorhanden sein
  + k&ouml;nnen.</para>
  + </note>
   
  -<para>
  -Armed with this knowledge, we are almost ready for the next
  -version of <filename>hex.asm</filename>. First, however, we need to
  -add a few lines to <filename>system.inc</filename>:
  -</para>
  + <para>Ausger&uuml;stet mit diesen Kenntnissen, sind wir beinahe bereit
  + f&uuml;r eine weitere Version von <filename>hex.asm</filename>.
  + Zuerst m&uuml;ssen wir jedoch noch ein paar Zeilen zu
  + <filename>system.inc</filename> hinzuf&uuml;gen:</para>
   
  -<para>
  -First, we need to add two new entries to our list of system
  -call numbers:
  -</para>
  + <para>Erstens ben&ouml;tigen wir zwei neue Eintr&auml;ge in unserer
  + Liste mit den Systemaufrufnummern:</para>
   
  -<programlisting>
  + <programlisting>
   %define SYS_open 5
   %define SYS_close 6
  -</programlisting>
  + </programlisting>
   
  -<para>
  -Then we add two new macros at the end of the file:
  -</para>
  + <para>Zweitens f&uuml;gen wir zwei neue Makros am Ende der Datei
  + ein:</para>
   
  -<programlisting>
  + <programlisting>
   %macro sys.open 0
           system SYS_open
   %endmacro
  @@ -1530,13 +1521,12 @@
   %macro sys.close 0
           system SYS_close
   %endmacro
  -</programlisting>
  + </programlisting>
   
  -<para>
  -Here, then, is our modified source code:
  -</para>
  + <para>Und hier ist schlie&szlig;lich unser ver&auml;nderter
  + Quelltext:</para>
   
  -<programlisting>
  + <programlisting>
   %include 'system.inc'
   
   %define BUFSIZE 2048
  @@ -1679,111 +1669,98 @@
           sub eax, eax
           sub ecx, ecx ; buffer is empty now
           ret
  -</programlisting>
  -
  -<para>
  -In our <varname>.data</varname> section we now have two new variables,
  -<varname>fd.in</varname> and <varname>fd.out</varname>. We store the input and
  -output file descriptors here.
  -</para>
  -
  -<para>
  -In the <varname>.text</varname> section we have replaced the references
  -to <varname>stdin</varname> and <varname>stdout</varname> with
  -<varname>[fd.in]</varname> and <varname>[fd.out]</varname>.
  -</para>
  -
  -<para>
  -The <varname>.text</varname> section now starts with a simple error
  -handler, which does nothing but exit the program with a return
  -value of <constant>1</constant>.
  -The error handler is before <varname>_start</varname> so we are
  -within a short distance from where the errors occur.
  -</para>
  -
  -<para>
  -Naturally, the program execution still begins at <varname>_start</varname>.
  -First, we remove <varname>argc</varname> and <varname>argv[0]</varname> from the
  -stack: They are of no interest to us (in this program, that is).
  -</para>
  + </programlisting>
   
  -<para>
  -We pop <varname>argv[1]</varname> to <varname role="register">ECX</varname>. This
  -register is particularly suited for pointers, as we can handle
  -NULL pointers with <function role="opcode">jecxz</function>. If <varname>argv[1]</varname>
  -is not NULL, we try to open the file named in the first
  -argument. Otherwise, we continue the program as before: Reading
  -from <varname>stdin</varname>, writing to <varname>stdout</varname>.
  -If we fail to open the input file (e.g., it does not exist),
  -we jump to the error handler and quit.
  -</para>
  + <para>In unserem <varname>.data</varname>-Abschnitt befinden sich nun

----------------------------------------------
Diff block truncated. (Max lines = 200)
----------------------------------------------

To Unsubscribe: send mail to majordomo(at)de.FreeBSD.org
with "unsubscribe de-cvs-doc" in the body of the message
Received on Thu 23 Aug 2007 - 17:51:28 CEST

search this site