EASy68K  
It is currently Thu Apr 09, 2020 6:30 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Dec 12, 2012 3:42 am 
Offline

Joined: Wed Dec 12, 2012 3:33 am
Posts: 3
so i am making a sub routine that reverses a string sent from the main routine using the address of the the string, size of string , and the address of the space i want the backward string, but im getting an error, can someone help me :D, im also only a semester old in 68k assembler programming just for reference.
so my main prog, right now im getting an error with my pea A0 commands .

project is
Quote:
First, your program will print a title line containing your name, programming assignment number, and your class account number, all on one line. Then you will prompt the user to enter a string. You will then make a reversed copy of the string entered by the user, and print a message "The reversed string is: " followed by the reversed string on the following line.

Your program will consist of two files:

prog4.s The 'main' program.
reverse.s The recursive subroutine that creates the reversed string.

Important: You must use exactly these file names. Remember that UNIX is case sensitive. If you use a different filename, it will not be collected by the grading program, and your project will fail to assemble.

The subroutine file contains the subroutine of the same name. Following is the prototype and behavior of the reverse subroutine:

Signature:
void reverse(char &in, char &out, int count)

Action:
The subroutine creates a reversed copy of the string that begins at the address in, that has the number of characters given by the parameter count, and writes the reversed copy starting at the address out

Load Point:
$7000

Parameters:

char &in The starting address of the string entered by the user.
char &out The starting address of the memory location where the reversed string is to be written.
int count The number of characters in the string to be reversed.

The subroutine must be recursive, and must use the following algorithm:

void reverse(char *in, char *out, int count) {
if(count == 0)
return;
reverse(in+1,out,--count);
*(out+count) = *in;
}

Additional details/requirements:

The prog4.s program reads the input string from the keyboard, calls the reverse subroutine, then prints the reversed string.
Remember that you must null terminate the output string before printing it.
You do not need to import iomacs.s or anything else in the subroutine. The subroutine does no I/O.
You may not allocate any storage in the subroutine.
Although it would be trivial to write a for loop to copy the string backwards, you may not do so. You must use the recurvsive algorithm specified. Programs that do not use recursion will receive no credit.
You may not reference 'global' values, either in registers or memory. You can only access values or references passed in as parameters.
Your subroutines must save state. You may not use a register in a subroutine that was not saved onto the stack first.
Your subroutines must follow standard protocols as covered in class.
You must assemble and load both files to run your program.



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
*
*----------------------------------------------------------------------
*
#minclude /home/ma/cs237/bsvc/iomacs.s
#minclude /home/ma/cs237/bsvc/evtmacs.s
*
*----------------------------------------------------------------------
*
* Register use
*
*----------------------------------------------------------------------
*
reverse:  EQU  $7000


start:    initIO              * Initialize (required for I/O)
        setEVT         * Error handling routines
*        initF         * For floating point macros only   

            * Your code goes HERE
                   
     lineout   info           *print out information
     lineout   prompt         *prompt user with question
     linein    buffer         *read string
     move.l    D0,D1          *get the length of the string.
   
   
     move.l    D1,-(SP)       *place count on the stack
     pea       backwr         *place address of out on the stack
     pea       buffer           *place address of in on the stack
     jsr       reverse        *call reverse
     adda.l    #12,SP         *reset SP
     
     
     lea       backwr,A0
     add.l     D1,A0
     clr.b     (A0)
     
     lineout   backwr
     
     
     
     
     
     
     
     
                   


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

            * Your storage declarations go
            * HERE
                   
buffer:   ds.b 80
info:     dc.b 'Program #4, XXXXXXXXXXXXXXX',0
prompt:   dc.b 'Enter a string',0
answer:   dc.b 'Here is the string backwards',0
backwr:   ds.b 80


        end




and my reverse subroutine.

Code:

*void reverse (char *in, char *out, int count)
*if (count == 0)
*return;
*reverse(in+1,out,--count);
* *(out+count) = *in;


        ORG  $7000
         
reverse: 
        link   A6,#0
        movem.l     D1/A0-A2,-(SP)
        movea.l     8(A6),A1       *in
        movea.l     12(A6),A0      *out
        move.l      16(A6),D1      *count
        TST.l       D1             *testing if count == 0
        BEQ         done           *if count == 0 move to done
        addq.l      #1,A1          *add 1 to in
        subq.l      #1,D1          *sub 1 from count
        move.l      D1,-(SP)       *move count onto stack
        pea    (A0)                  *move out onto stack
        pea    (A1)                  *move in onto stack
        jsr        reverse
        adda.l      #12,SP         *pushing stack back
        move.l      A0,A2          *Copying out
        add.l       D1,A2          *adding count to out
        move.b      (A1),(A2)      *out+count = byte @ A1
             
done:   
        movem.l     (SP)+,D1/A0-A2 *replacing previous values
        unlk   A6                  *unlinking

        rts
        end






EDIT: changed pea A0, pea A1, to pea (A0), pea (A1)


Last edited by kneecapped on Wed Dec 12, 2012 4:52 am, edited 2 times in total.

Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 3:52 am 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
You can't PEA an address register. Either use MOVE.l or use indirection, (), on the register.

Lee.


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 3:58 am 
Offline

Joined: Wed Dec 12, 2012 3:33 am
Posts: 3
ok so i changed,
pea A0
pea A1


to

pea (A0)
pea (A1)

to push those to addresses back onto the stack,SP
put when i run prog4.s
i don't get an output.
just this

Quote:
Program #4, XXXXXXXXXX
Enter a string
string


is there anything in my code that would cause this that stands out.?


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 4:22 am 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Yes, your reverse routine dumps the last pushed values even if it didn't call itself.

Lee.


Top
 Profile  
 
PostPosted: Wed Dec 12, 2012 6:44 am 
Offline

Joined: Wed Dec 12, 2012 3:33 am
Posts: 3
Well i got it to work :D
This one works :D
Code:
*void reverse (char *in, char *out, int count)
*if (count == 0)
*return;
*reverse(in+1,out,--count);
* *(out+count) = *in;


        ORG  $7000

reverse:
        link   A6,#0
        movem.l     D1/A0-A2,-(SP)
        movea.l     8(A6),A1       *in
        movea.l     12(A6),A0      *out
        move.l      16(A6),D1      *count
        TST.l       D1             *testing if count == 0
        BEQ         done           *if count == 0 move to done
        move.l      A1,A2
        addq.l      #1,A2          *add 1 to in
        subq.l      #1,D1          *sub 1 from count
        move.l      D1,-(SP)       *move count onto stack
        pea    (A0)                  *move out onto stack
        pea    (A2)                  *move in onto stack
        jsr        reverse
        adda.l      #12,SP         *pushing stack back

        add.l       D1,A0          *adding count to out
        move.b      (A1),(A0)      *out+count = byte @ A1

done:
        movem.l     (SP)+,D1/A0-A2 *replacing previous values
        unlk   A6                  *unlinking

        rts
        end


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
*
*----------------------------------------------------------------------
*
#minclude /home/ma/cs237/bsvc/iomacs.s
#minclude /home/ma/cs237/bsvc/evtmacs.s
*
*----------------------------------------------------------------------
*
* Register use
*
*----------------------------------------------------------------------
*
reverse:  EQU  $7000


start:    initIO              * Initialize (required for I/O)
             setEVT                     * Error handling routines
*            initF                      * For floating point macros only

                                * Your code goes HERE

     lineout   info           *print out information
     lineout   prompt         *prompt user with question
     linein    buffer         *read string
     move.l    D0,D1          *get the length of the string.


     move.l    D1,-(SP)       *place count on the stack
     pea       backwr         *place address of out on the stack
     pea       buffer           *place address of in on the stack
     jsr       reverse        *call reverse
     adda.l    #12,SP         *reset SP


     lea       backwr,A0     *null the end of the string
     add.l     D1,A0
     clr.b     (A0)

     lineout   backwr











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

                                * Your storage declarations go
                                * HERE

buffer:   ds.b 80
info:     dc.b 'Program #4, XXXXXXXXXXXXXX',0
prompt:   dc.b 'Enter a string',0
answer:   dc.b 'Here is the string backwards',0
backwr:   ds.b 80


        end


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 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