⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manual.txt

📁 open source of basic interpreter of 68
💻 TXT
📖 第 1 页 / 共 5 页
字号:
                 Note that, unlike traditional Basics, SB68k does not
                 automatically initialize all variables to zero.  The value
                 of any variable following system reset is unknown!  Your
                 SB68k program must provide any needed variable
                 initialization.
                 SB68k also supports single-dimension arrays, or vectors.
                 Each element in a vector array occupies one 32-bit location
                 (four bytes).  You use the DECLARE statement to define a
                 vector array in much the same way you use it to define a
                 simple variable.  For example:
                     declare  foo(5)
                 defines the vector array FOO, consisting of five sequential
                 32-bit locations.  The first element in any vector array is
                 always element zero.  Thus, FOO in the above example
                 consists of the five elements named FOO(0) through FOO(4).
                 SB68k also supports double-dimension arrays.  Each element
                 in a 2D array occupies one 32-bit location (four bytes).
                 You use the DECLARE statement to define a 2D array in much
                 the same way you use it to define a vector array.  For
                 example:
                                       Page 19

                     declare  foo(5,4)
                 defines the 2D array FOO, consisting of 20 sequential 32-bit
                 locations.  The first element in a 2D array is always
                 element (0,0).  Thus, FOO in the above example consists of
                 the 20 elements named FOO(0,0) through FOO(4,3).  When using
                 2D array, remember that the elements are arranged in memory
                 with the first subscript incrementing faster.  Thus, the map
                 for the 2D array FOO would look like:
                 FOO(0,0), FOO(1,0), FOO(2,0), ... FOO(2,3), FOO(3,3),
                 FOO(4,3)
                 You can use arrays anywhere a variable name would be legal,
                 including the left side of an assignment operator.  For
                 example:
                     declare  foo(5,4)
                     foo(2,0) = 100/n
                 SB68k allows you to create named 32-bit constants.  You
                 create constants with the CONST statement.  For example:
                     const  bar = 34
                 creates the SB68k constant BAR with a value of 34.  CONST
                 statements may refer to previously defined constants, and
                 may include any number of math operations.  CONST statements
                 may not, however, refer to variables, as the contents of
                 variables are not known at compile-time.  If you refer to a
                 variable inside a CONST statement, the compiler will report
                 an error.
                 You must create a constant before your code can reference
                 that constant.  This means that you will usually place all
                 CONST statements in a block at the beginning of your SB68k
                 source file.
                 Note that named constants do not consume any space in the
                 final executable file.  They only exist as equates in the
                 assembler source file generated by SBasic.
                                            Page 20

                 Data tables
                 SB68k allows you to store tables of data in ROM, for access
                 by your program at run-time.  This technique is used often
                 for storing pre-defined information, such as lookup tables
                 for motor speeds or mathematical functions.
                 To store 32-bit values in a data table, use the DATA
                 statement.  Follow the DATA statement with a list of values
                 to be written into ROM.  For example:
                      data      0, 1, 2, 3          ' store 4 32-bit values
                 in table
                 SB68k will generate suitable assembly language source to
                 store the values into code memory at the current location.
                 For the 68000, this example would generate assembly language
                 source similar to:
                      dc.l      0,1,2,3
                 To store 16-bit values in a data table, use the DATAW
                 statement.  Follow the DATAW statement with a list of values
                 to be written into ROM.  For example:
                      dataw     1234, 5678, $1111, $4321 ' store 4 16-bit
                 values                                            ' in table
                 SB68k will generate suitable assembly language source to
                 store the values into code memory at the current location.
                 For the 68000, this example would generate assembly language
                 source similar to:
                      dc.w      $04d2,$162e,$1111,$4321
                 To store 8-bit values in a data table, use the DATAB
                 statement.  Follow the DATAB statement with a list of values
                 to be written into ROM.  For example:
                      datab     $ff, 123, 256, 'z'  ' store 4 8-bit values
                 SB68k will generate suitable assembly language source to
                 store the values into code memory at the current location.
                 For the 68000, this example would generate assembly language
                 source similar to:
                      dc.b      $ff,$7b,$00,$7a
                 Note that the third value appears in the SB68k source as
                 256, but is converted to 0 in the output source file.  This
                 happens because SB68k only writes the low eight bits of a
                 DATAB list item to the output file.
                                       Page 21

                 In order to access items within a DATA (or DATAB or DATAW)
                 table, you must provide a label at the start of the list.
                 Your program can then use this label to find the first item
                 in the list.  For example:
                      declare   n
                      declare   sum
                      foo:
                      data      1,2,3,4
                      data      5,6,7,8
                      main:
                      sum = 0
                      for  n = 0 to 7
                           sum = sum + peek(addr(foo) + n * 4)
                      next
                      end
                 This code uses the ADDR() function to locate the start of
                 the data table at label FOO.  The list item of interest is
                 found by adding an offset value (N * 4) to the address of
                 FOO.  The PEEK() function then reads the 32-bit value stored
                 at that address in the table.
                 To use the above technique with a DATAW table, you must
                 change PEEK() to PEEKW() and replace the multiplication by 4
                 in the offset calculation with a multiplication by 2.  To
                 use the above technique with a DATAB table, you must change
                 PEEK() to PEEKB() and remove the multiplication by 4 in the
                 offset calculation.
                 Note that SB68k writes a DATA table in place.  That is, the
                 table appears in exactly the same position in the output
                 file as it appears in your SB68k source file.
                 This means you cannot place a DATA table inside a block of
                 executable code.  If you do, the target MCU will eventually
                 try to execute the DATA table as if it were machine code,
                 and your program will crash.
                 For that reason, put your DATA statements outside of
                 executable blocks.  A good place to write DATA statements is
                 immediately before the MAIN: label in your program.
                                            Page 22

                 COPY statement
                 SB68k provides the COPY statement, used to move data from
                 one memory area to another.  This proves very handy when you
                 need to initialize a large array.  Format of the COPY
                 statement is:
                      copy  from, to, count
                 where FROM is the address of the data block, TO is the
                 address of the destination area, and COUNT is the number of
                 BYTES (not variables) to move.
                 For example, assume you need to initialize the array FOO
                 with a table of data, already existing in a block of DATA
                 statements.  You would use statements similar to:
                      declare  foo(10)
                      table:
                      data     $1234, $5678, $1, $2, $3, $4
                      data     $5, $6, $7, $8
                      copy  addr(table), addr(foo), 40
                 This code uses the ADDR() function to locate the addresses
                 of the TABLE data block and the FOO array, then moves 40
                 bytes of data from the table to the array.
                 Note that COPY cannot be used to move data into an area of
                 memory that overlaps the source area.  Should you need to
                 perform this operation, use two COPY statements, first to
                 move the data into an intermediate area, then to move it
                 into the final destination area.
                                       Page 23

                 Operators
                 SB68k supports all of the common arithmetic operators:
                 = (equal-sign) sets the value of a variable to the result of
                 a calculation.  This is the traditional assignment operator.
                 All assignments store a 32-bit value into a variable.
                 + (plus-sign) performs 32-bit addition.
                 - (minus-sign) performs 32-bit subtraction.  It also acts as
                 the unary negation operator.
                 ~ (tilde) performs 32-bit one's complement.  This is
                 logically identical to N XOR $ffffffff.
                 * (asterisk) multiplies two 32-bit signed values, yielding a
                 32-bit product.
                 Run-time support for SBasic68k's multiplication operator on
                 a 68000 MCU relies on a library file, included with the
                 SB68k distribution.  This file is automatically added to the
                 assembler source file created by SBasic68k, whenever your
                 program invokes the multiplication operator.
                 Note that this library file is only included if your code
                 uses a multiply operation.  You can create smaller
                 executables by eliminating any use of the multiplication
                 operator, if appropriate.
                 / (forward-slash) divides a 32-bit dividend by a 32-bit
                 divisor, yielding a 32-bit quotient; the remainder is lost.
                 Run-time support for SBasic68k's division operator on a
                 68000 MCU relies on a library file, included with the SB68k
                 distribution.  This file is automatically added to the
                 assembler source file created by SBasic68k, whenever your
                 program invokes the multiplication operator.
                 Note that this library file is only included if your code
                 uses a divide operation.  You can create smaller executables
                 by eliminating any use of the division operator, if
                 appropriate.
                 MOD (modulus) divides a 32-bit dividend by a 32-bit divisor,
                 yielding a 32-bit remainder; the quotient is lost.
                 Run-time support for SBasic68k's division and MOD operators
                 on a 68000 MCU relies on a library file, included with the
                 SB68k distribution.  This file is automatically added to the
                 assembler source file created by SBasic68k, whenever your
                 program invokes either operator.
                                            Page 24

                 Note that this library file is only included if your code
                 uses a division or MOD operation.  You can create smaller
                 executables by eliminating any use of these operators, if
                 appropriate.
                 Examples:
                      alpha = foo + bar        ' adds two variables
                      beta = gamma - $1234     ' subtracts a hex constant
                      var1 = 3 * var2          ' multiplies a variable
                      c = delta / 88           ' divides a variable by a
                 constant
                      m = gamma MOD 10         ' takes the modulus function
                 SB68k also supports most of the common Boolean operators:
                 AND performs the logical AND of two 32-bit values.
                 OR performs the logical inclusive-OR of two 32-bit values.
                 XOR performs the logical exclusive-OR of two 32-bit values.
                 Examples:
                      alpha = foo AND $7f      ' leaves only low 7 bits of
                 foo
                      beta = alpha OR 255      ' sets all low 8 bits of alpha
                      gamma = beta XOR $ffffffff    ' inverts all bits in
                 beta

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -