Docstoc

skt-inputoutput

Document Sample
skt-inputoutput Powered By Docstoc
					                            Using My Input/Output Subroutines
                                              (Tewksbury)



Contents
1. Some Generalities                                                                                  1
   1.1 Adding a Subroutine Within Your Assembly Language Program                                      1
   1.2 Adding a Subroutine Not Integrated Within Your Assembly Language Program                       2
   1.3 Using the #include xxx.asm Instruction to Specify Subroutine Memory Locations                  2
   1.4 Preserving Contents of Registers When Using Subroutines                                        2
   1.5 What Input/Output Functions are Provided?                                                      3
2. The SKTINCS.ASM File                                                                               4
3. CMD-12DP512 Memory Map                                                                             4
4. Following is the Manual                                                                            5
5. Example Program                                                                                    8
6. Running Subroutines on Simulator and on EVB                                                        9


1. Some Generalities

1.1 Adding a Subroutine Within Your Assembly Language Program
Imagine that you have written an assembly language program such as
                      org            $5000
        x1            dc.b           $24
        x2            dc.b           $56

        main          org       $4000
                      ldaa      x1
                      adda      x2
                      .... etc.
                      ldab      $34
                      addb      x1
        here          bra       here ; Branch back on itself forever.
Next, assume you add a program (a subroutine sub1) as follows:
        sub1            org           $4522
                        ... instructions
                        rts
where the rts instruction says “return from subroutine.”
Next, you wish to “call” the subroutine sub1 from your main program. Simply add the jsr sub1(jump to
subroutine sub1) instruction to your main program. The input/output subroutines in the sktsubs programs
are used in this manner.



                                                                                                      1
1.2 Adding a Subroutine Not Integrated Within Your Assembly Language Program
Now suppose you wish to call another subroutine sktsub2, from a set of three subroutines (sktsubs)
already built by someone and provided to you as an .s19 file. Suppose that other person’s assembly
language program (before building and obtaining the .s19 file) was something like

                       org            $1e46

        sktsub1        ... instructions
                       rts
        sktsub2        ... instructions
                       rts
        sktsub3        ... instructions
                       rts
The sktsubs.s19 file you received does not tell you the memory address of the first instruction for the
subrt2 subroutine.
To use those subroutines, the other person must provide you with the addresses of the memory locations
where the three subroutines are stored in the microprocessor when the sktsubs.s19 file is uploaded to the
microprocessor. This can be accomplished using a set of EQU statements that you add to the start of your
program, e.g.,
        sktsub1        EQU            $1e46
        sktsub2        EQU            $2a44
        sktsub3        EQU            $2af3

1.3 Using the #include xxx.asm Instruction to Specify Subroutine Memory Locations
Typing in all of these EQU lines is tedious if sktsubs contains a large number of subroutines. Instead, you
can be provided with a file (.asm file) containing these EQU statements. Let sktkincs.asm be the file
containing the three EQU statements above. The assembler will automatically add the EQU statements of
the sktkincs.asm file if you use a #include “sktsincs.asm” statement at the top of your program if the file
is in the same folder as your program. (here the quotation marks are optional - but recommended) If this
file is in another folder, you can include a path such as in #include “../sktsubs/ sktsincs.asm”. In this
latter case, the file and path must be included in quotation marks.
Note: The subroutine names in the #include file may not be redefined in your assembly language
program (otherwise, there will be a multiple definition error).

1.4 Preserving Contents of Registers When Using Subroutines
When your program calls a subroutine, there will be data stored in the various registers (A, B, X, Y, etc.).
We will see later a way in which you can save and then restore the data in those registers when calling a
subroutine. For the sktsubs set of subroutines, this saving of register data is completed at the start of the
subroutine and the register data is restored just before the rts return from the subroutine. You will not
need to worry about this issue. However, the input subroutines of the sktsubs program do use a register
(A register for 8-bit values, D register for 16-bit values) to store the value of the keyboard input(s)
returned to the main program. The manual in Section 4 and the summary in Section 1.5 specify the
registers used (their values before calling the subroutine are not preserved).




                                                                                                            2
1.5 What Input/Output Functions are Provided?
The basic types of input/output functions are listed here (see Section 5 for details)
General I/O
    sktcrlf: Print carriage return and line feed (like “endl” in C++). No register.
    sktwait Delay loop. No register.
Text
       sktinch: Input single ASCII character (into B register), no line feed and no echo.
       sktoutch: Output single ASCII character (from B register)
       sktint: Input text including carriage returns up to the esc key (esc changed to NULL by program.
        Starting address of memory location where text will be stored must be in X index register
       sktout: Output text up to NULL ($00)
        Starting address of memory location of text to be output must be in X index register
Input Data in Hex Format
    sktinhb: Input 8-bit number in hex format into B register
    sktinhw: Input 16-bit number in hex format into D register
Input Unsigned Data in Decimal Format
    sktindb: Input unsigned 8-bit number in decimal format into B register
    sktindw: Input unsigned 16-bit number in decimal format into D register
Input Signed Data in Decimal Format
    sktinsgnb: Input signed 8-bit number in decimal format into B register
    sktinsgnw: Input signed 16-bit number in decimal format into D register
Output Data in Hex Format
    sktoutbh: Output 8-bit number from B register in hex format
    sktoutwh: Output 16-bit number from D register in hex format
Output Unsigned Data in Decimal Format
    sktoutbd: Output unsigned 8-bit number from B register in decimal format
    sktoutwd: Output unsigned 16-bit number from D register in decimal format
Output Signed Data in Decimal Format
    sktoutsgnb: Output signed 8-bit number from B register in decimal format
    sktoutsgnw: Output signed 16-bit number from D register in decimal format




                                                                                                       3
2. The SKTINCS.ASM File
   To use, add #include “sktincs.asm” as first line of your program. You can then use these labels in
   your program. You can also include the full path to sktincs.asm, e.g. , #include
   “../sktsubs/sktincs.asm” within quotation marks. That file is as follows.
       sktcrlf            equ         $100b
       sktinch            equ         $1018
       sktindb            equ         $126c
       sktindw            equ         $12d8
       sktinhb            equ         $138b
       sktinhw            equ         $13d4
       sktinsgnb          equ         $14ff
       sktinsgnw          equ         $1556
       sktint             equ         $1049
       sktoutbd           equ         $1077
       sktoutbh           equ         $11c7
       sktoutch           equ         $1022
       sktoutt            equ         $102c
       sktoutwd           equ         $10dc
       sktoutwh           equ         $1201
       sktwait            equ         $1000
       sktoutsgnb         equ         $14d8
       sktoutsgnw         equ         $152d
Note: Variables used in sktsubs are stored in memory locations $2000 - $212F. The program sktsubs
      occupies memory space $1000 - $158C

3. CMD-12DP512 Memory Map
     ADDRESS             MEMORY TYPE                        MEMORY APPLICATION
  $0000 - $03FF       S12 Registers               Memory mapped addresses of internal registers.
                                                  Must Not Use.
  $0400 - $0FFF       Internal EEPROM and         Monitor reserved. Must Not Use.
                      some Internal RAM
  $1000 - $3DFF       User Internal RAM           Available for User program, if needed. Do Not
                                                  Use if using SKTSUBS for input/output.
  $3E00 - $3F8B       Internal RAM                Monitor reserved RAM memory. Must Not Use.
  $3F80 - $3FFd       Internal RAM                Ram Interrupt Vector Table. Must Not Use.
  $4000 - $7FFF       External RAM                User Program Memory. Your programs
                                                  go here
  $8000 - $BFFF       Flash/External RAM          User Paged Program Memory. Do Not Use.
  $C000 - $FFFF       Flash                       Mon12 and Utility Firmware. Must Not Use.




                                                                                                        4
4. Following is the Manual
The following list summarizes the subroutines I created for CpE390, including use with the HC12 Java-
based simulator. You are expected to be familiar with what subroutines are available and able to use
them to allow keyboard input and display output in your assembly language programs.
The list includes the name of the subroutine (in bold red) followed by (also in bold red) the starting
address location for the subroutine. Memory locations between $1000 and $2600 are used for the
subroutines and should not be used for your programs.
Note: There is an include file with the actual addresses (to be used as a header file in your program)
included with the files in this zipped directory. The instruction for adding the header file sktincs.asm to
your program (done at the start like #include <> in C++) is
   #include “sktincs.asm” or #include “<path>/sktincs.asm”.


sktwait ($1000): Delay loop ($1000 times).
    No inputs to subroutine
    No outputs from subroutine
sktcrlf ($100B): Print carriage return plus line feed
     No inputs to subroutine
     No outputs from subroutine
sktinch ($1018): Input a single character from the keyboard
     No inputs to subroutine
     Output from the subroutine is the character (ASCII code) returned in B register
     Note: Click on simulator display window to activate keyboard
sktoutch ($1022): Output a single character to the display
     Input to subroutine is the character to output which must be in B register before calling sktoutch
     No outputs from the subroutine
sktoutt ($102C): Outputs a null terminated text file (including carriage returns) to display
     Input to subroutine is the starting address of the text file which must be in the X index register
        before calling the subroutine. The end of the text file must be the NULL character ($00) so that
        the program will know where the text file ends.
     No outputs returned by the subroutine.
     Note: if the starting address is given by a label (e.g., XXX), you must include a "#" sign in front
        to load the address into the X register. Otherwise you would be loading the first two characters of
        the string into the X register.
sktint ($1049): Inputs an "esc" terminated text file (which can include carriage returns) from the
      keyboard
     Input to subroutine is the starting address of the memory location in which the text will be saved.
        This starting address must be in the X index register before calling the subroutine.
     Output from the subroutine is the text entered, stored at the starting address provided in the X
        register when calling the subroutine
     Note: The only way to complete the input of the text string is to end the string with the "esc"
        (escape) key on your keyboard.




                                                                                                              5
       The subroutine converts the "esc" character into the NUL character ($00) to correctly designate
        the end of the text file.
sktoutbd ($1077): Prints an 8-bit unsigned hexidecimal number (byte) in decimal format. For example,
     the binary number $2d in the computer will display as "45", its decimal value.
     Input to subroutine is the byte to be printed, which must be in the B register
     No outputs returned by the subroutine
     Note: The display displays only ascii characters. If you try to print a byte stored in the B register
       directly (with sktoutch), the ascii character for this byte will be displayed. For example, the byte
       $07 output with sktoutch will cause the bell to ring. This subroutine sktoutbd converts the byte
       into the three characters (including the leading "$").

sktoutsgnb ($14D8): Prints an 8-bit signed hexidecimal number (byte) in decimal format. For example,
     the binary number $2d in the computer will display as "+45", its decimal value with the sign (+ or -
     ) shown.
     Input to subroutine is the byte to be printed, which must be in the B register
     No outputs returned by the subroutine.
sktoutwd ($10DC): Prints a 16-bit hexidecimal number (word) in decimal format. For example, the
     binary number $2d1b in the computer will display as "11547", its decimal value.
     Input to subroutine is the 16-bit word to be printed, which must be in the D register
     No outputs returned by the subroutine
     Note: See note for sktoutbd.
sktoutsgnw ($152D): Prints a 16-bit signed hexidecimal number (word) in decimal format. For
     example, the binary number $2d1b in the computer will display as "+11547", its decimal value with
     the sign (+ or -) shown.
     Input to subroutine is the 16-bit word to be printed, which must be in the D register
     No outputs returned by the subroutine
     Note: See note for sktoutbd.
sktoutbh ($11C7): Prints an 8-bit hexidecimal number (byte) in hexidecimal format. For example, the
     binary number $2d in the computer will display as "$2d".
     Input to subroutine is the byte to be printed, which must be in the B register
     No outputs returned by the subroutine
sktoutwh ($1201): Prints a 16-bit hexidecimal number (word) in hexidecimal format. For example, the
     binary number $2d1b in the computer will display as "$2d1b".
     Input to subroutine is the 16-bit word to be printed, which must be in the D register
     No outputs returned by the subroutine

sktindb ($126C): Inputs an 8-bit unsigned hexidecimal number (byte) typed on the keyboard in decimal
      format. For example, entering the decimal number "45" will generate the binary number $2d in the
      computer
     No inputs to the subroutine
     The number entered must include three decimal digits. Use leading zeroes as needed (e.g., +013).
        Allowed values are between 000 and 255.
     The byte returned by the subroutine is in the B register.




                                                                                                          6
sktinsgnb ($14FF): Inputs an 8-bit signed hexidecimal number (byte) typed on the keyboard in decimal
      format. For example, entering the decimal number "+45" will generate the binary number $2d in
      the computer
     No inputs to the subroutine
     The number entered must include first the sign and then three decimal digits, with allowed values
        between -128 and + 127. Use leading zeroes as needed (e.g., +013). Numbers outside of this
        range will convert to incorrect numbers (with no warning given to the user).
     The byte returned by the subroutine is in the B register.
sktindw: ($12D8): Inputs an 16-bit unsigned hexidecimal number (word) typed on the keyboard in
      decimal format. For example, entering the decimal number "11547" will generate the binary
      number $2d1b in the computer
      No inputs to the subroutine
      The number entered must include five decimal digits. Use leading zeroes as needed (e.g., 00013).
      Allowed values are between 00000 and 65535. Numbers outside of this range will generally be
       accepted but will be converted to meaningless numbers (with no warning given to the user).
      The byte returned by the subroutine is in the D register.
sktinsgnw ($1556): Inputs an 16-bit signed hexidecimal number (byte) typed on the keyboard in decimal
      format. For example, entering the decimal number "+11547" will generate the binary number
      $2d1b in the computer.
     No inputs to the subroutine
     The number entered must include first the sign and then five decimal digits. Use leading zeroes as
        needed (e.g., -00013).
     Allowed values are between -32768 and + 32767. Numbers outside of this range will generally be
        accepted but will be converted to meaningless numbers (with no warning given to the user).
     The byte returned by the subroutine is in the D register.
sktinhb ($138B): Inputs an 8-bit hexidecimal number (byte) typed on the keyboard in hexidecimal
      format. For example, entering the decimal number "$2d" on the keyboard will generate the binary
      number $2d in the computer
     No inputs to the subroutine
     The byte returned by the subroutine is in the B register.
     Note: The leading dollar sign is required when entering number on keyboard and two hex
        numbers must be included immediately after the "$" (e.g., $2d).
sktinhw ($13D4): Inputs an 16-bit hexidecimal number (byte) typed on the keyboard in hexidecimal
      format. For example, entering the decimal number "$2d1b " on the keyboard will generate the
      binary number $2d1b in the computer
     No inputs to the subroutine
     The byte returned by the subroutine is in the D register.
     Note: The leading dollar sign is required when entering number on keyboard and four hex
        numbers must be included immediately after the "$" (e.g., $4d56).




                                                                                                        7
5. Example Program
#include "../sktsubs/sktincs.asm" ;Addresses for subroutines

        ORG     $5000 ;Start of variable space
X1      DC.B    'd'
X2      DC.B    'g'
PMT     DC.B    "Enter a character ", $00
SPC     DC.B    " ", $00

        ORG     $4000

start ldx       #pmt    ; Want address of string, not ‘E’ ‘n’
      jsr       sktoutt ; Display prompt
      jsr       sktinch ; Input single character (no line feed)
      ldx       #spc    ; Want address of string
      jsr       sktoutt ; Output two spaces
      jsr       sktoutch ; Echo character back to display

        addb    #$2    ; Add 2 to character
        ldx     #spc   ; Want address of string
        jsr     sktoutt       ; 2 spaces after echo
        jsr     sktoutch ; Output character +2
        jsr     sktcrlf ; Carriage return & line feed
        bra     start   ; Return to start for next character
here    bra     here    ; Program in infinite wait loop
        end             ; End of assembly file




                                                                  8
6. Running Subroutines on Simulator and on EVB
Two subroutine files sktsubs-sim.s19 and sktsubs-evb.s19 were included with the zip file. Actually, both
are the same and either can be on the simulator and the lab EVB.
When used on the simulator:
       Load your program’s .s19 file into the simulator.
       Load the DBUG12.s19 file into the simulator
       Load the sktsubs-sim.s19 file into the simulator
       Under the “Files” pull-down menu, click “Reset”. This is the same as clicking the reset button on
        your EVB.
       Open the SCI viewer.
       Click Go on the simulator. You will get a BDN message that you should ignore. Simply close
        the window showing the message.
       The instruction showing should indicate a branch to memory location $4000. This is where your
        program should start.
       Click Go again and your program will start running. If you wish to enter data from the keyboard,
        you will first have to click on the SCI viewer window (a red cursor will appear). When the red
        cursor is present, you can enter data/text from the keyboard.


When used on the EVB:
       Load your program’s .s19 file into the EVB.
       DO NOT LOAD the DBUG12.s19 file into the simulator
       Load the sktsubs-sim.s19 (or the sktsubs-evb.s9) file into the EVB
       Reset the EVB
       Start running your program at whatever memory location you used (e.g., $4000) with an ORG
        statement to define the start of the program instructions.
In both cases above, you may find that strange characters appear on your screen in addition to the
expected. This is an example of a bug in a non-commercial set of input/output subroutines. Somewhere,
there is an error but I haven’t found it yet.




                                                                                                           9

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:12/19/2010
language:English
pages:9