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

Address Error
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1309
Page 1 of 1

Author:  Grassy1 [ Mon Apr 21, 2014 10:59 pm ]
Post subject:  Address Error

I am currently working on a code asking about calculating and printing prime numbers from the range of 2-65535. I have the code just about done, but I keep on getting an address error at the BSVC. I'm also getting a warning about the ASCII exceeding four characters on the line with the '65535.'

Here's my code:

Code:
again:       
            lineout     prompt 
             linein      buffer
     
      *Check String Length     
            tst.l   D0
            beq     BAD
            cmpi.l  #5,D0
            bgt     BAD
     
      *Loop and validate digits
            move.w  D0,D7
            subq.w  #1,D7
            lea     buffer,A0
       
Ck:         
            cmpi.b  #'0',(A0)
            blo     BAD
            cmpi.b  #'9',(A0)+
            bhi     BAD
            dbra    D7,Ck
            bra     next
           
BAD:           
            bra   again
next:     
            cvta2 buffer,D0           
   
            * Check range
            cmpi.l  #'2',D0
            blt     BAD
            cmpi.l  #'65535',D0
            bgt     BAD
            move.l  D0,D1
   
            * Factor Loop
            moveq #2,D2  *factor = 2
       
For:       
            cmp.w  D1,D2
             bgt    DONE
             move.l D1,D7
             andi.l #$0000FFFF,D7 ** Address error 3166 from the .lis file
             divu   D2,D7
             swap   D7
             tst.w  D7
             bne    endif
   
            move     D2,D0       * answer += factor + "*" 
            andi.l   #$0000FFFF,D0
            cvt2a   (A0),#5
            stripp   (A0),#5
            adda.l   D0,A0
            move.l   #'*',(A0)+
            andi.l  #$0000FFFF,D1
            divu    D2,D1
            subq.w #1,D2
endif:
        addq.w      #1,D2
        bra         For           
DONE:
       
   
    *** Prompt to continue
        *y / n part
DO:
    ori.b       #$20,buffer *input lowercase
    cmpi.b      #'y',buffer
    beq         DO
    cmpi.b      #'n',buffer
    beq         DONE
   

endloop:
        dbra D2,factor

        *Print answer
        lea factor,A2
        lea answer,A3
         
         
        move.b  #'a',(A0)+
        move.b  #'r',(A0)+
        move.b  #'e',(A0)+
        move.b  #':',(A0)+
        clr.b   (A0)
        lineout answer
        lineout factor
           
***prompt to go again...           
   
    break                   * Terminate execution
*
*----------------------------------------------------------------------
*       Storage declarations

title   dc.b    'Program 3',0
skipln  dc.b    0
prompt  dc.b    'Enter an integer to factor (2...65535)',0
answer  dc.b    'The factors of '
buffer  ds.b    80
factor  ds.b    40

        end
code tags added by admin

Author:  profkelly [ Tue Apr 22, 2014 3:48 pm ]
Post subject:  Re: Address Error

The source will not assemble as listed. The source code to your macros is missing.

Author:  Grassy1 [ Tue Apr 22, 2014 6:43 pm ]
Post subject:  Re: Address Error

Opps forgot about that. I was able to fix the ascii error, I figured out I had to remove the single quotes (forgot I was dealing with numbers instead of a string). However, I am still getting an address error before address 0000 3166.
*----------------------------------------------------------------------
*
ORG $0
DC.L $3000 * Stack pointer value after a reset
DC.L start * Program counter value after a reset
ORG $3000 * Start at location 3000 Hex
*
*----------------------------------------------------------------------
*
#minclude /home/ma/cs237/bsvc/iomacs.s
#minclude /home/ma/cs237/bsvc/evtmacs.s
*
*----------------------------------------------------------------------
*
* Register use
*
*----------------------------------------------------------------------
*
start: initIO * Initialize (required for I/O)
setEVT * Error handling routines
* initF * For floating point macros only

lineout title
lineout skipln

again: lineout prompt
linein buffer

tst.w D0 *Check String Length
beq BAD
cmpi.l #5,D0
bgt BAD

move.l D0,D7 *Loop and validate digits
subq.l #1,D7
lea buffer,A0

Ck: cmpi.b #'0',(A0)
blo BAD
cmpi.b #'9',(A0)+
bhi BAD
dbra D7,Ck
bra next

BAD:
bra again


next: cvta2 buffer,D0
cmpi.l #2,D0
blt BAD
cmpi.l #65535,D0
bgt BAD
move.l D0,D1

For: moveq #2,D2 *factor = 2
cmp.w D1,D2
bhi DONE
move.l D1,D7
andi.l #$0000FFFF,D7
divu D2,D7
swap D7
tst.w D7
bne endif

move D2,D0 * answer += factor + "*"
andi.l #$0000FFFF,D0
cvt2a (A0),#5
stripp (A0),#5
adda.l D0,A0
move.l #'*',(A0)+
andi.l #$0000FFFF,D1
divu D2,D1
subq.w #1,D2
endif: addq.w #1,D2
bra For
DONE:

move.b #'a',(A0)+
move.b #'r',(A0)+
move.b #'e',(A0)+
move.b #':',(A0)+
clr.b (A0)
lineout answer
lineout factor

endloop: dbra D2,factor
bra DO

DO: lineout continue
linein buffer
ori.b #$20,buffer *input lowercase
cmpi.b #'y',buffer
beq DO
cmpi.b #'n',buffer
beq exit

exit:

break * Terminate execution
*
*----------------------------------------------------------------------
* Storage declarations

title dc.b 'Program #3',0
skipln dc.b 0
prompt dc.b 'Enter an integer to factor (2...65535)',0
answer dc.b 'The factors of '
continue dc.b 'Do you want to continue?',0
buffer ds.b 80
factor ds.b 40

end

Author:  Grassy1 [ Wed Apr 23, 2014 3:35 pm ]
Post subject:  Re: Address Error

Ok, I fixed my address error. Now I'm just having an issue ending the for loop.

Code:
        ORG     $0     
        DC.L    $3000           * Stack pointer value after a reset
        DC.L    start           * Program counter value after a reset
        ORG     $3000           * Start at location 3000 Hex
*
*----------------------------------------------------------------------
*
* Register use
*
*----------------------------------------------------------------------
*
start: initIO                  * Initialize (required for I/O)
            setEVT                         * Error handling routines
*          initF                              * For floating point macros only           
                     lineout     title     
            lineout     skipln
 
again:       lineout     prompt
             linein      buffer
           
            tst.w   D0 *Check String Length
            beq     BAD
            cmpi.w #5,D0
            bgt     BAD
           
            move.w D0,D7 *Loop and validate digits
            subq.w #1,D7
            lea     buffer,A0
       
Ck:         cmpi.b #'0',(A0)
            blo     BAD
            cmpi.b #'9',(A0)+
            bhi     BAD
            dbra    D7,Ck
          bra     next
           
BAD:           
            bra   again
         
           
next:      cvta2   buffer,D0
            cmpi.w #2,D0
            blt     BAD
            cmpi.w #65535,D0
            bgt     BAD
            move.w D0,D1
   
For:        moveq #2,D2 *factor = 2
            cmp.w D1,D2
             bhi    DONE
             move.w D1,D7
             andi.l #$0000FFFF,D7
             divu   D2,D7
             swap   D7
             tst.w D7
             bne    endif
 
            move     D2,D0       * answer += factor + "*"
            andi.l   #$0000FFFF,D0
            cvt2a   (A0),#5
            stripp   (A0),#5
            adda.l   D0,A0
            move.l   #'*',(A0)+
            andi.l #$0000FFFF,D1
            divu    D2,D1
            subq.w #1,D2
endif:      addq.w      #1,D2
            bra         For           
DONE:
        lea factor,A2   *Print output
        lea answer,A3
           move.b #'a',(A0)+
            move.b #'r',(A0)+
            move.b #'e',(A0)+
            move.b #':',(A0)+
            clr.b   (A0)
            lineout answer
EndL: dbra D2,For
       
DO: lineout    continue
    linein     buffer   
    cmpi.w      #1,D0
    ori.b       #$20,buffer *input lower case
    cmpi.b      #'y',buffer
    beq         DO
    cmpi.b      #'n',buffer
    beq         exit
exit:       
 
    break                   * Terminate execution
*
*----------------------------------------------------------------------
*       Storage declarations
title   dc.b    'Program #3',0
skipln dc.b    0
prompt dc.b    'Enter an integer to factor (2...65535)',0
answer dc.b    'The factors of '
continue dc.b   'Do you want to continue?',0
buffer ds.b    80
factor ds.b   40
        end
code tags added by admin

Author:  profkelly [ Wed Apr 23, 2014 9:24 pm ]
Post subject:  Re: Address Error

D2 is being reloaded with 2 at the start of the loop. Move the For: label down one line to the CMP.W D1,D2 instruction.

Author:  Grassy1 [ Thu Apr 24, 2014 4:56 pm ]
Post subject:  Re: Address Error

Thank you, that helped me out quite abit. : ) I just have a few more things to tweak and I am on my way.

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