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

I can't seem to get the answer to display
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1266
Page 1 of 1

Author:  raymondyjtan [ Sun Dec 08, 2013 5:27 am ]
Post subject:  I can't seem to get the answer to display

My program is searching " Searching for the lowest ODD integer"

Code:
START:                  ; first instruction of program
    ORG $8000
DATA DS.B 10
MSG1 DC.B 13,'PLEASE DO NOT ENTER MORE THAN 5 NUMBERS',13,13,0
MSG2 DC.B 13,13,' YOU HAVE ENTERED MORE THAN 5 CHARACTERS!'
     DC.B ' ERROR',13,13,0
MSG3 DC.B 10,10,10,7,'THE LOWEST ODD INTEGER IS ',0
MSG4 DC.B 10,10,10,10,0

    ORG $9000
LOOP    CLR.L D5
        CLR.L D7
        MOVE.B #0,D2
        MOVEA.L $8000,A5
        LEA     MSG1,A3
        TRAP #15
       

READ    TRAP #0
        CMPI.B #13,D1
        BEQ LOOP
        TRAP #1
        ADDQ.B #1,D2
        CMPI.B #6,D2
        BEQ ERROR
        BRA READ



TEST    DIVU #2,D2
        SWAP D2
TEST2   SUBQ.W #1,D2
        BNE TEST2
        BRA RESULT

RESULT  LEA  MSG3,A3
        TRAP #3
        MOVE.B D3,$8500
        MOVEA.L #$8500,A3
        TRAP #3
        LEA MSG4,A3
        TRAP #3
        BRA DONE

ERROR   LEA MSG2,A3
        TRAP #3

DONE    TRAP #15
        TRAP #9
    END START
code tags added by admin

Author:  gtippery [ Wed Dec 25, 2013 1:08 pm ]
Post subject:  Re: I can't seem to get the answer to display

I think you have more problems than getting the answer to display. Did you try stepping through the code to see if you are getting an answer? I think it's crashing.

Quote:
Code:
START:                  ; first instruction of program
    ORG $8000
DATA DS.B 10

Do you see where it says "first instruction"? That means the next thing shouldn't be data...

Quote:
My program is searching " Searching for the lowest ODD integer"

You need to provide a better description. For instance, searching where (file? console? specified range of memory? stack?), for (signed, unsigned?) integers represented how (B,W,L,BCD,ASCII)? And doing what with the result?

Quote:
Code:
MSG2 DC.B 13,13,' YOU HAVE ENTERED MORE THAN 5 CHARACTERS!'
     DC.B ' ERROR',13,13,0

1) Consecutive CR's don't change the output. If you want multiple lines, you need multiple LF's.
2a) If you intend " ERROR" to be part of MSG2, but on a separate line, you need CR,LF before it.
2b) If you intend " ERROR" to be a separate message, it needs a label.

Quote:
Code:
    ORG $9000
LOOP    CLR.L D5
        CLR.L D7
        MOVE.B #0,D2
        MOVEA.L $8000,A5

3) You should use the labels you put in, not absolute addresses: LEA DATA,A5

You need comments:
4) Any particular reason for $9000?
5) What are you using D5 and D7 to do? (What's the significance of the values you put in them?)
6) What do you intend to do with A5? You never reference it again.
7) Also, the label LOOP is misleading, as you apparently only return to here if there's an error. Maybe RETRY? That is, if you need to branch here at all, otherwise no label.
Quote:
Code:
READ    TRAP #0
        CMPI.B #13,D1
        BEQ LOOP
        TRAP #1
        ADDQ.B #1,D2
        CMPI.B #6,D2
        BEQ ERROR
        BRA READ

8) Under what condition does the BEQ LOOP branch? It appears to restart the program if the user presses CR.
9) What do you expect TRAP #0 to do? Did you intend Task #0 instead? I think you may want Task #5.
10) TRAP #1 probably isn't what you want.
11) Comment that D2 is your character counter.
12) BEQ, BRA: You need to rethink your logic here. There's no way to get to the next section of code (TEST).

I'm not going to look for any further logic errors at this time.

Quote:
Code:
        BRA RESULT

RESULT  LEA  MSG3,A3

There's no point in branching to the next instruction.

Other TRAP instructions you used are probably also not what you intend.

Minor point: DIVU is an inefficient way to check for oddness of an integer. You only need to check the lowest bit. There are multiple ways to do it, such as using BTST, ANDI, or a right shift.

Correct these and similar errors, add comments, try stepping through the code while watching the registers to check your logic, and ask again if you're still stuck.

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