<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title> words/number.asm </title>
    <meta name="keywords" content="amforth programming language Forth ATmega ATMEL">
    <meta name="description" content="amforth - laguage Forth for ATMEL ATmega">
    <!-- AUTOINCLUDE START "Page/Head.en.ihtml" DO NOT REMOVE -->
    <link rel="StyleSheet" href="../../../../Web/CSS/MLAB.css" type="text/css" title="MLAB Basic Style">
    <link rel="StyleSheet" href="../../../../Web/CSS/MLAB_Print.css" type="text/css" media="print">
    <link rel="shortcut icon" type="image/x-icon" href="../../../../Web/PIC/MLAB.ico">
    <script type="text/javascript" src="../../../../Web/JS/MLAB_Menu.js"></script>
    <!-- AUTOINCLUDE END -->
  </head>

  <body lang="en">

    <!-- AUTOINCLUDE START "Page/Header.en.ihtml" DO NOT REMOVE -->
    <!-- ============== HEADER ============== -->
    <div class="Header">
      <script type="text/javascript">
      <!--
        SetRelativePath("../../../../");
        DrawHeader();
      // -->
      </script>
      <noscript>
        <p><b> JavaScript is required for including of the header </b></p>
      </noscript>
    </div>
    <!-- AUTOINCLUDE END -->

    <!-- AUTOINCLUDE START "Page/Menu.en.ihtml" DO NOT REMOVE -->
    <!-- ============== MENU ============== -->
    <div class="Menu">
      <script type="text/javascript">
      <!--
        SetRelativePath("../../../../");
        DrawMenu();
      // -->
      </script>
      <noscript>
        <p><b> JavaScript is required for including of the menu </b><p>
      </noscript>
    </div>
    <!-- AUTOINCLUDE END -->

    <!-- ============== TEXT ============== -->
    <div class="Text">

      <h1> words/number.asm </h1>

      <p>
        <input type=button onClick="history.back()" value="Back">
        <input type=button onClick="history.forward()" value="Forward">
        <a href="../WordList.en.html">Jump to Vocabulary</a>
      </p>

      <pre>
; (addr -- n ) Numeric IO
; R( -- )
; convert a word to a number, throw exception -1 on error
VE_NUMBER:
    .db $06, &quot;number&quot;,0
    .dw VE_HEAD
    .set VE_HEAD = VE_NUMBER
XT_NUMBER:
    .dw DO_COLON
PFA_NUMBER:
    ; sign flag
    .dw XT_DOLITERAL
    .dw 1             ; ( -- addr 1)
    .dw XT_ZERO       ; ( -- addr 1 0)
    .dw XT_ROT        ; ( -- 1 0 addr)
    .dw XT_COUNT      ; ( -- 1 0 addr' len)
    .dw XT_ZERO
    .dw XT_DODO
    .dw PFA_NUMBER6
PFA_NUMBER1: ; ( n addr -- )
    .dw XT_DUP
    .dw XT_I
    .dw XT_PLUS
    .dw XT_CFETCH
    ; now check for +/- signs
    .dw XT_DUP
    .dw XT_DOLITERAL
    .dw $2d ; '-'
    .dw XT_EQUAL
    .dw XT_DOCONDBRANCH
    .dw PFA_NUMBER2
    .dw XT_DROP
    ; replace the sign flag
    .dw XT_ROT
    .dw XT_DROP
    .dw XT_DOLITERAL
    .dw -1
    .dw XT_ROT
    .dw XT_ROT
    .dw XT_DOBRANCH
    .dw PFA_NUMBER4
PFA_NUMBER2:
    .dw XT_BASE
    .dw XT_FETCH
    .dw XT_DIGIT
    .dw XT_EQUALZERO
    ; check for non number characters and stop converting if found
    .dw XT_DOCONDBRANCH
    .dw PFA_NUMBER3
    .dw XT_DOLITERAL
    .dw -13
    .dw XT_THROW
PFA_NUMBER3:
    .dw XT_ROT
    .dw XT_BASE
    .dw XT_FETCH
    .dw XT_MUL
    .dw XT_PLUS
    .dw XT_SWAP
PFA_NUMBER4:
    .dw XT_DOLOOP
    .dw PFA_NUMBER1
PFA_NUMBER6:
    .dw XT_DROP
    ; incorporate sign into number
    .dw XT_SWAP
    .dw XT_LESSZERO
    .dw XT_DOCONDBRANCH
    .dw PFA_NUMBER5
    .dw XT_NEGATE
PFA_NUMBER5:
    .dw XT_EXIT
</pre>

      <p>
        <input type=button onClick="history.back()" value="Back">
        <input type=button onClick="history.forward()" value="Forward">
        <a href="../WordList.en.html">Jump to Vocabulary</a>
      </p>

    </div>

    <!-- AUTOINCLUDE START "Page/Footer.en.ihtml" DO NOT REMOVE -->
    <!-- ============== FOOTER ============== -->
    <div class="Footer">
      <script type="text/javascript">
      <!--
        SetRelativePath("../../../../");
        DrawFooter();
      // -->
      </script>
      <noscript>
        <p><b> JavaScript is required for including of the footer </b></p>
      </noscript>
    </div>
    <!-- AUTOINCLUDE END -->

  </body>
</html>