EASy68K  
It is currently Thu Apr 02, 2020 1:18 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Issue with strings
PostPosted: Tue May 05, 2009 3:44 am 
Offline

Joined: Tue May 05, 2009 3:32 am
Posts: 1
Iv got an issue.
I run the simulator and i input characters, the program loops letting me input more until i press [Enter].
Once i press enter the program then counts each character and display it. The problem is that i cant find out how to determine the end of a string that the user inputs.

Quote:
next move.b #5,d0
trap #15
cmp.b #cr,d1
beq clear
move.b d1,(a6)+
bra next

clear clr.b d1
bra count

count move.b (a6)+,d2
cmp.b [????],d2
beq count_finish
add.b #1,d1
bra count


its the [???] im not sure about


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 05, 2009 11:01 am 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
How about storing 0 at the end of the string to NULL terminate it.

Code:
next move.b #5,d0
    trap #15
    cmp.b #cr,d1
    beq clear
    move.b d1,(a6)+
    bra next

clear clr.b d1
    move.b d1,(a6)+     ; null terminate string
    bra count

count lea  buffer,a6    ; a6 points to start of string
    move.b (a6)+,d2
    beq count_finish
    add.b #1,d1
    bra count

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 08, 2009 3:06 pm 
Offline

Joined: Fri Dec 19, 2008 1:12 pm
Posts: 37
Or, for fun, try this:

Code:
    lea     buffer,a6    ; a6 points to start of string
next
    moveq   #5,d0
    trap    #15
    move.b  d1,(a6)+
    cmp.b   #cr,d1
    bne     next

clear
    move.b  #0,-(a6)
    moveq   #-1,d1       ; start counting at -1 to exclude end of string
    lea     buffer,a6    ; a6 points to start of string

count
    addq.l  #1,d1
    cmp.b   #0,(a6)+
    bne     count


If the method for determening the string length can be anything, then this will work, too. Instead of counting the chars in the string afterwards, it's done while reading them from the keyboard. The string length is stored in d2, and is zero terminated like strings in C.

Code:
    lea     buffer,a6    ; a6 points to start of string
    moveq   #-1,d2       ; start counting at -1 to exclude #cr
next
    moveq   #5,d0
    trap    #15
    move.b  d1,(a6)+
    addq.l  #1,d2
    cmp.b   #cr,d1
    bne     next

clear
    move.b  #0,-(a6)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 30, 2011 8:12 pm 
Offline

Joined: Mon Mar 21, 2011 11:44 pm
Posts: 5
Location: Jamaica
what is #cr in this code?

_________________
:) Thank You


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 30, 2011 8:47 pm 
Offline

Joined: Mon Jul 26, 2010 11:43 pm
Posts: 198
Location: Aurora, IL
chevi wrote:
what is #cr in this code?


Carriage Return, ($0D or 13), the ENTER/RETURN key

Line Feed, ($0A or 10), sometimes referred to as LF

These would be ASCII control characters.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Group