EASy68K  
It is currently Wed Sep 19, 2018 5:51 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Aug 22, 2009 2:14 pm 
Offline

Joined: Fri Jul 10, 2009 10:32 am
Posts: 8
Location: Hawaii
i have this code below and i can't figure out what seems to be the problem. there are no errors about my syntax but when i run the program i don't get an output. the simulator shows an error message of

Address Error: Instruction at 13 accessing address 13
Address Error: Instruction at 13 accessing address 13
Address or Bus error during exception processing. Execution halted

my program is decimal-to-binary conversion.
Code:
ORG   $1000
DIGIT1   DC.B   '1'      ; ones place value of the input
DIGIT2   DC.B   '2'      ; tens place value of the input
DIGIT3   DC.B   '3'      ; hundreds place value of the input
   
INPUT   DS.B   3      ; reserves 3 bytes of memory for the input
OUTPUT   EQU   $3000      ; indicates that memory location 3000 would be the OUTPUT location
SP   EQU   $2004      

START:            ; first instruction of program
   MOVE.L #INPUT,-(SP)   ; pushes the address of INPUT on the stack
   MOVE.L #OUTPUT,-(SP)   ; pushes the address of OUTPUT on the stack
   BSR GETSTORE      ; branches to subroutine GETSTORE
   
GETSTORE
   MOVE.L 8(SP),A0      ; gets the address of the stack and storing it to A0
   MOVE.B DIGIT3,0(A0)   ; places DIGIT3 on the first byte of INPUT
   MOVE.B DIGIT2,1(A0)   ; places DIGIT2 on the second byte of INPUT
   MOVE.B DIGIT1,2(A0)   ; places DIGIT1 on the third byte of INPUT
   
   MOVE.L A0,-(SP)
   BSR CONVERSION
   RTS
   
CONVERSION
   MOVE.L 4(SP),A1
   MOVE.L 8(SP),A2
   MOVE.B (A1)+,D3      
   MOVE.B (A1)+,D2
   MOVE.B (A1),D1
   SUB.B #$30,D3
   MULS #100,D3
   SUB.B #$30,D2
   MULS #10,D2
   SUB.B #30,D1
   CLR D4
   ADD D1,D4
   ADD D2,D4
   ADD D3,D4
   MOVE D4,(A2)
   MOVEM.L A1-A3/D1-D4,-(SP)
   RTS
   
   MOVE.B   #9,D0
   TRAP   #15      ; halt simulator

* Variables and Strings

   

   END   START      ; last line of source
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 22, 2009 6:07 pm 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
All kinds of wrong here not limited to what I'm about to point out ..

Code:
CONVERSION
   MOVE.L 4(SP),A1
   MOVE.L 8(SP),A2            ; ** A2 is now the return address for the
                              ; ** GETSTORE subroutine
   MOVE.B (A1)+,D3
   MOVE.B (A1)+,D2
   MOVE.B (A1),D1
   SUB.B #$30,D3
   MULS #100,D3
   SUB.B #$30,D2
   MULS #10,D2
   SUB.B #30,D1
   CLR D4
   ADD D1,D4
   ADD D2,D4
   ADD D3,D4
   MOVE D4,(A2)               ; ** you just overwrote the MOVE.L 8(SP),A0
                              ; ** in GETSTORE
   MOVEM.L A1-A3/D1-D4,-(SP)  ; ** and now you filled the stack
                              ; ** with data before trying to RTS
   RTS


Lee.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 22, 2009 6:08 pm 
Offline

Joined: Wed Jul 29, 2009 5:36 pm
Posts: 9
Location: Ptolemaios
I noticed that you pushed register value into the stack, making the top of the stack point to a value 13. Upon reaching the RTS part, the value 13 is loaded into the PC instead of the correct returning address for that subroutine i.e. 1030.

_________________
Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 23, 2009 2:23 am 
Offline

Joined: Fri Jul 10, 2009 10:32 am
Posts: 8
Location: Hawaii
how will i be able to fix the contents of my stack? i cant understand why my stack has the address of the GETSTORE subroutine. could you please elaborate more. Thank You


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group