EASy68K
http://www.easy68k.com/EASy68Kforum/

Cannot do BSR properly
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1283
Page 1 of 1

Author:  snoopybbt [ Thu Jan 16, 2014 7:08 pm ]
Post subject:  Cannot do BSR properly

Hey guys, really sorry for bothering, but I just can't get this code to run properly:

Code:
*-----------------------------------------------------------
* Title      : Convert a string from lowercase to uppercase
* Written by :
* Date       : JAN 3, 2014
* Description:
*-----------------------------------------------------------

        ORG    $1000

s:      DC.B    'Today is an awesome day',0

        ORG    $2000
       
        MOVE.L #$8000, A7  ; STACK SETUP
       
START:                  ; first instruction of program
        PEA s
        BSR STAMPA
DSPLY:  LEA s, A1
        MOVE.B #14, D0
        TRAP #15
   

STAMPA: MOVE.L (A7)+, A0
BGIN:   MOVE.B (A0), D0
        BEQ RET
        CMP #'a', D0
        BLT NEXT
        CMP #'z', D0
        BGT NEXT
        SUB #32, D0
        MOVE.B D0, (A0)
NEXT:   ADD #1, A0
        BRA BGIN
RET:    RTS


END:    SIMHALT             ; halt simulator

* Put variables and constants here

    END    START        ; last line of source



I get the following error:

Quote:
PC=0000200A Code=6100 BSR
Address Error: Instruction at 106d accessing address 106d


What is going wrong?

Thanks in advance,
--
Snoopy

Author:  gtippery [ Sat Jan 18, 2014 1:35 am ]
Post subject:  Re: Cannot do BSR properly

Well, the first thing I notice is this:
Quote:
Code:
        ORG    $2000
       
        MOVE.L #$8000, A7  ; STACK SETUP
       
START:                  ; first instruction of program

This MOVE.L instruction will never be executed, because you're declaring the first instruction to be after it. Therefore the stack won't be where you expect. In this case, it doesn't matter. On real hardware, it would.

The second thing I notice is the lack of comments telling what you intend your code to be doing. Example:
Code:
STAMPA: MOVE.L (A7)+, A0   Pop passed address of string

Next, when your error message refers to a specific address, I'd be nice to be able to see what's at that address, perhaps by including part of the list file:
Code:
0000200A  6100 000C                 18          BSR STAMPA


Moving on, I think the error message may be misleading you. The fatal error you get is a consequence of the way you're using the stack. Open the stack window, step through the program and observe the stack upon entering STAMPA, and what A0 is after the first instruction of STAMPA.

As far as this specific error message, I get the same error on this code fragment:
Code:
   ORG   $1000
START:
   NOT  Doors+1 *** Addressing error on this instruction ***
   SIMHALT      ; halt simulator

Doors   DCB.B   100,0   ;Reserve 100 bytes, prefilled with zeros

   END   START

Error is:
Quote:
Address Error: Instruction at 1000 accessing address 100b

Here the problem seems to be accessing memory declared as bytes as a word; using NOT.B works. This is not the same as your error, but it's related. You're using (accessing) memory in an unexpected fashion.

I have not checked for any other errors.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/