EASy68K  
It is currently Sat Apr 04, 2020 7:04 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue May 23, 2006 9:35 am 
Offline

Joined: Tue May 23, 2006 3:06 am
Posts: 2
I've been told to print a string of characters at a passed memory address (user input of up to 100 characters) and terminating it with a null, while passing the parameters on the stack. I'm having trouble understanding what I have to pass on the stack in order to print the string, and how to terminate with #00. Currently I'm doing as follows:
Code:
next      move.l     #str,a2
          bsr        input
          move.b     d0,(a2)+
          cmp.b      #cr,d0
          beq        exit
          bsr        output
          bra        next
input     move.b     #247,d7
          trap       #14
          rts
output    move.b     #248,d7
          trap       #14
          rts
exit      move.b     #228,d7
          trap       #14
          org        $1500
str       ds.b       100
          end


All this does is to print the input. I don't have much idea as to how to apporach the requirements, like what to do with -(sp).
Any suggestions? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 3:50 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
Is the null terminated string already in memory?

Are you just passing the pointer to the string to the subroutine?

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 3:59 pm 
Offline

Joined: Tue May 23, 2006 3:06 am
Posts: 2
No, its not already in memory. I'm supposed to somehow add null to the end of the "input string". The program I'm writing is about determining the longest word in a sentence and printing it.
I have to write a subroutine which can print this string (and other strings stored in memory, such as "The longest word is:"). In the subroutine I'd compare #null with the input to stop printing characters.

In the past couple of hours I've come up with
Code:
;continued
        cmp.b   #cr,d0
        bne     to_stk
        move.b  #null,(a2)+   ; moves null to the end I hope
        move.l  a2,-(sp)
        bsr     prnt_str
....................................
prnt_str  move.w   4(sp),a4
          move.b   (a4)+,d0
          cmp.b    #null,d0
          bne      cprnt
          rts
cprnt     bsr      output
          bra      prnt_str




Might make more sense as to what my dilemma is I hope.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 7:30 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
EASy68K trap tasks 13 or 14 will display a null terminated string. Set register A1 to the address of the string.

Trap task 2 will read a string from the keyboard, add a null terminator to the end and store it in memory pointed to by register A1.

A null terminator is just the binary number 0 so you can easily put it anywhere in a string to terminate the string.

See the EASy68K help for all the trap tasks that are available. Look at the examples in the EASy68K/Examples folder for help on using the trap tasks.

_________________
Prof. Kelly


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