Printing a string by parameters
Page 1 of 1

Author:  Demolit [ Tue May 23, 2006 9:35 am ]
Post subject:  Printing a string by parameters

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:
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
output    move.b     #248,d7
          trap       #14
exit      move.b     #228,d7
          trap       #14
          org        $1500
str       ds.b       100

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.

Author:  profkelly [ Tue May 23, 2006 3:50 pm ]
Post subject: 

Is the null terminated string already in memory?

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

Author:  Demolit [ Tue May 23, 2006 3:59 pm ]
Post subject: 

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
        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
cprnt     bsr      output
          bra      prnt_str

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

Author:  profkelly [ Tue May 23, 2006 7:30 pm ]
Post subject: 

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group