M L

Need Assembly Help

Discussion created by M L on Jun 8, 2007
Latest reply on Jun 8, 2007 by Simon Marsden
Hello everyone, I am a teaching assistant and i am in need of some help.  Our students used to use a 68k chip and there are numerous labs that go along with it.

My job is to test these labs using the mcf5211DEMO board.  I am unfamiliar with CodeWarrior 6.4 Coldfire and I am unable to even get the option to create a project in assembly.  Can someone direct me as to how to test to make sure the programs (each instruction) will still run on the board?  I've included an example of a previous lab.

TIA!
~M

*******************************************************************************
*
* Program that performs BCD arithmetic on data from the parallel port.
*
*******************************************************************************

* Set the assembler options, cre turns on cross-reference in the listing file
* and mex turns on macro expansion in the listing file.
    opt     cre,mex

*******************************************************************************
* Definitions for access to and control of the ACIA chip
ACIA_CR    equ    $E0000        ; Control Register address
ACIA_DR    equ    $E0002        ; Data Register address
* Control Register (7..0) Bit definitions:
*  7    Receive Interrupt Enable
*  6..5    RTS control / Transmit interrupt control
*    00 = RTS=Low, Transmit interrupt disabled
*          01 = RTS=Low, Transmit interrupt enabled
*          10 = RTS=High, Transmit interrupt disabled
*          11 = RTS=Low, TxD=Break, Transmit interrupt disabled
*  4..2    Communication configuration
*    000 = 7E2
*    001 = 7O2
*    010 = 7E1
*    011 = 7O1
*    100 = 8N2
*    101 = 8N1
*    110 = 8E1
*    111 = 8O1
*  1..0    Clock divider / Master Reset
*    00 = Divide by 1
*    01 = Divide by 16
*    10 = Divide by 64
*    11 = Master Reset
* Control register values:
SER_RST    equ    $03        ; CR1=CR0=1 causes master reset
SER_8N1    equ    $15        ; 4..2=8N1, Divide by 16
*******************************************************************************
* Definitions for access to and control of the PIA chip
* Port A Data Register
PIA_DRA      equ    ($E8001+$0)
* Port A Data Direction Register
PIA_DDRA     equ    ($E8001+$0)
* Port A Control Register
PIA_CRA      equ    ($E8001+$2)

* Port B Data Register
PIA_DRB      equ    ($E8001+$4)
* Port B Data Direction Register
PIA_DDRB     equ    ($E8001+$4)
* Port B Control Register
PIA_CRB      equ    ($E8001+$6)

* Control Register - Select Data Direction Register
SEL_DDR      equ    $00
* Control Register - Select Data Register
SEL_DR       equ    $04

* Data Direction Register - Select Input Port
SEL_INP      equ    $00
* Control Register - Select Output Port
SEL_OUTP     equ    $FF
*******************************************************************************

* Set the starting address of the program.
    org        $20000

start
* Initialize the stack
    MOVEA.L    #$23C00,A7

* Waste some time ~1sec. (wait for ACIA to be inactive)
           MOVE.L     #$0002FF00,D0
DELAY:     SUBQ.L     #1,D0
           BNE        DELAY

* Initialize ACIA #1 chip
* Reset the chip using "master reset"
           MOVE.B     #SER_RST,ACIA_CR
* Setup the communication protocol
           MOVE.B     #SER_8N1,ACIA_CR

* Initialize the PIA #1 chip
* Select the Data Direction Register for Port A
    MOVE.B    #SEL_DDR,PIA_CRA
* Setup Port A for output to LEDs
    MOVE.B    #SEL_OUTP,PIA_DDRA
* Select the Data Register for Port A
    MOVE.B    #SEL_DR,PIA_CRA
* Select the Data Direction Register for Port B
    MOVE.B    #SEL_DDR,PIA_CRB
* Setup Port B for input from switches
    MOVE.B    #SEL_INP,PIA_DDRB
* Select the Data Register for Port B
    MOVE.B    #SEL_DR,PIA_CRB
REPEAT:
* Prompt the user to set the switches for A
            MOVE.B      #0,d0
    LEA        M0,A1
    MOVEQ      #LENM0,D1
    BSR    SBC_IO
* Wait for a key to be pressed...
    MOVE.B     #5,D0
    BSR    SBC_IO
* Read the switches
    MOVE.B    PIA_DRB,D0
           MOVE.B     D0,BCD_A
* Prompt the user to set the switches for B
           MOVE.B     #0,d0
    LEA        M1,A1
    MOVEQ      #LENM1,D1
    BSR    SBC_IO
* Wait for a key to be pressed...
    MOVE.B     #5,D0
    BSR    SBC_IO
* Read the switches
    MOVE.B    PIA_DRB,D0
    MOVE.B    D0,BCD_B
* Calculate the BCD sum A-23+B
        MOVE.B     #$23,D0
    MOVE.B    BCD_A,D1
    MOVE.B    BCD_B,D2
* Initialize the CCR, X=0 and Z=1
    MOVE.W    #%00100,CCR
* Compute A-23
        SBCD       D0,D1
* Check to see if result is less than 0 (indicated by a carry-out)
    BCS    OUT_RANGE
* Compute A-23+B
           ABCD       D2,D1
* Check to see if result is greater than 99 (indicated by a carry-out)
    BCC    IN_RANGE
* Display 'out of range' message
OUT_RANGE:
           MOVE.B     #1,d0
    LEA        M3,A1
    MOVEQ      #LENM3,D1
    BSR    SBC_IO
* Clear the result (and the LEDs) since it is not correct
    CLR.B    D1
IN_RANGE:
* Display the result on the LEDs
    MOVE.B    D1,PIA_DRA
* Prompt the user to contiue
           MOVE.B     #0,d0
    LEA        M2,A1
    MOVEQ      #LENM2,D1
    BSR    SBC_IO
* Get the user response
    MOVE.B     #5,D0
    BSR    SBC_IO
* Compare the response - repeat if it was 'Y'
    CMP.B    #'Y',D1
    BEQ    REPEAT

* Stop executing
            JMP         $48C

*******************************************************************************
*  This subroutine implements *some* of the Teesside simulator TRAP I/O
*
* D0.B : Description (blank descriptions are not implemented)
*
* 0: Print string pointed at by A1 and D1.W characters long with CRLF
* 1: Print string pointed at by A1 and D1.W characters long without CRLF
* 2: Read the string pointed at by A1.  Length returned in D1.W (maximum 80)
* 3:
* 4:
* 5: Read a single character in D1.B
* 6: Print a single character in D1.B
* 7:
* 8:
* 9:
*
*******************************************************************************
sbc_io:
* Save registers
        MOVEM.L D0,-(SP)
* Dispatch table / switch() statement
    CMP.B    #0,D0
    BEQ    SUB_0
            CMP.B       #1,D0
            BEQ         SUB_1
    CMP.B    #2,D0
    BEQ    SUB_2
    CMP.B    #5,D0
            BEQ         SUB_5
    CMP.B    #6,D0
            BEQ         SUB_6
* Default for unimplemented subfunctions is to simply exit, an error is better
    JMP    EXIT_IO
*******************************************************************************
* Print the string pointed at by A1 and D1.W characters long with CRLF
SUB_0:   
* setup loop by decrementing LCV
    SUBI.W    #1,D1
    CMP.W    #-1,D1
    BEQ    CRLF
NEXT_0:
* Check to see if the ACIA is ready for a character
    MOVE.B    ACIA_CR,D0
    BTST.B    #1,D0
    BEQ    NEXT_0
* The ACIA is ready, send it the character
    MOVE.B    (A1)+,ACIA_DR
    DBF    D1,NEXT_0
CRLF:
CR_WAIT:
* Check to see if the ACIA is ready for a character
    MOVE.B    ACIA_CR,D0
    BTST.B    #1,D0
    BEQ    CR_WAIT
* The ACIA is ready, send it the CR
    MOVE.B    #$0D,ACIA_DR
* Check to see if the ACIA is ready for a character
LF_WAIT:
    MOVE.B    ACIA_CR,D0
    BTST.B    #1,D0
    BEQ    LF_WAIT
* The ACIA is ready, send it the LF
    MOVE.B    #$0A,ACIA_DR
* Done. Go to the subroutine exit
    JMP    EXIT_IO
*******************************************************************************
* Print the string pointed at by A1 and D1.W characters long without CRLF
SUB_1:
* setup loop by decrementing LCV
    SUBI.W    #1,D1
    CMP.W    #-1,D1
            BEQ         DONE_1
NEXT_1:
* Check to see if the ACIA is ready for a character
    MOVE.B    ACIA_CR,D0
    BTST.B    #1,D0
            BEQ         NEXT_1
* The ACIA is ready, send it the character
    MOVE.B    (A1)+,ACIA_DR
            DBF         D1,NEXT_1
DONE_1:
    JMP    EXIT_IO
*******************************************************************************
* Read the string pointed at by A1.  Length resturned in D1.W (max 80)
SUB_2:   
* Clear Count register
    CLR.W    D1
NEXT_2:
* Check to see if the ACIA has a character
    MOVE.B    ACIA_CR,D0
    BTST.B    #0,D0
            BEQ         NEXT_2
* The ACIA has a character, get it the character
            MOVE.B      ACIA_DR,D0
* See if the character is "enter"
    CMP.B    #$0D,D0
    BEQ    DONE_2
* Save the character
            MOVE.B      D0,(A1)+
    ADDI.W    #1,D1
    JMP    NEXT_2
DONE_2:
            JMP         EXIT_IO
*******************************************************************************
* Read a single character in D1.B
SUB_5:   
* Check to see if the ACIA has a character
    MOVE.B    ACIA_CR,D0
    BTST.B    #0,D0
    BEQ    SUB_5
* The ACIA has a character, get it the character
    MOVE.B    ACIA_DR,D1
    JMP    EXIT_IO
*******************************************************************************
* Print single character in D1.B
SUB_6:   
* Check to see if the ACIA is ready for a character
    MOVE.B    ACIA_CR,D0
    BTST.B    #1,D0
    BEQ    SUB_6
* The ACIA is ready, send it the character
    MOVE.B    D1,ACIA_DR
    JMP    EXIT_IO
EXIT_IO:
* Restore Resisters
            MOVEM.L     (SP)+,D0
* Return from subroutine
    RTS

*******************************************************************************
* Constants are placed at the end of the program.
*******************************************************************************
m0        dc.b        'Enter the BCD value for A on the switches'
lenm0     equ         *-m0
m1        dc.b        'Enter the BCD value for B on the switches'
lenm1     equ         *-m1
m2        dc.b        'Enter Y to continue: '
lenm2     equ         *-m2
m3        dc.b        'The result is out of range (0-99) and cannot be displayed!'
lenm3     equ         *-m3

*******************************************************************************
* Variables are placed in RAM
*******************************************************************************
* Set the starting address of RAM data
          org         $22000
BCD_A     ds.b        1
BCD_B     ds.b        1
          end         start



 

Outcomes