It is currently Fri Apr 10, 2020 2:47 am

 All times are UTC

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: HELP PLEASEPosted: Fri Nov 09, 2012 12:06 pm

Joined: Thu Nov 08, 2012 6:07 pm
Posts: 12
Hi all, can anyone tell me who to solve this:
In the main program:

 Pass it to SUB1 as a define address and size of string

 Display the new string on terminal

 In the SUB1:
 Convert the ASCII number to binary number

 Pass two consecutive numbers in string to SUB2 as a format of stack

 Convert the addition result from SUB2 to ASCII

 In SUB2:
 Do the same operation for all number in string.

Top

 Post subject: Posted: Fri Nov 09, 2012 3:10 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
I'm sure there are many people on this forum that could solve this problem. None of them will however, because we do not do student homework for them. That would defeat its purpose. Attempt the solution on your own and ask us specific questions about your program and we will help.

_________________
Prof. Kelly

Top

 Post subject: Posted: Sat Nov 10, 2012 5:03 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
This simplest way to pass values to and from a subroutine is in registers. Using registers requires coordination between the calling code and the subroutine as to which registers to use.

Using the stack to pass values is a bit more involved but does not require tracking register usage between the calling code and the subroutine.

Here is an example program that demonstrates calling a subroutine using both parameter passing techniques.

Code:
*-----------------------------------------------------------
* Program Number: Tutorial 4 for EASy68k
* Written by    : Chuck Kelly
* Date Created  : Nov-10-2012
* Description   : This program prompts for and gets 2 numbers from the keyboard.
*                 A subroutine is called to add the 2 numbers and return the sum.
*                 Adder1 subroutine uses registers to pass the parameters.
*                 Adder2 subroutine uses the stack to pass the parameters.
* This program is public domain.
*-----------------------------------------------------------

START   ORG \$1000

* The parameters and return value are passed using registers
move    #14,D0      task 14, display string
lea     prompt,A1   address of string to display in A1
trap    #15         trap #15 performs task

move    #4,D0       task 4, input number into D1.L
move.l  D1,D2       D2 = num1

move    #14,D0      task 14, display string
lea     prompt,A1   address of string to display in A1
trap    #15         trap #15 performs task

move    #4,D0       task 4, input number into D1.L
trap    #15         perform task, D1 = num2

bsr     Adder1      D1 = D1 + D2

move    #14,D0      task 14, display string
lea     result,A1   address of string to display in A1
trap    #15         trap #15 performs task
move    #3,D0       task 3, display number in D1.L
trap    #15         trap #15 performs task

bsr     newLine

* The parameters and return value are passed on the stack
move    #14,D0      task 14, display string
lea     prompt,A1   address of string to display in A1
trap    #15         trap #15 performs task

move    #4,D0       task 4, input number into D1.L
move.l  D1,-(SP)    push num1

move    #14,D0      task 14, display string
lea     prompt,A1   address of string to display in A1
trap    #15         trap #15 performs task

move    #4,D0       task 4, input number into D1.L
move.l  D1,-(SP)    push num2
move.l  #0,-(SP)    make room for sum on the stack

bsr     Adder2      sum = num1 + num2
move.l  (SP)+,D1    pull sum from stack, D1 = sum
lea     (8,SP),SP   clean up the stack

move    #14,D0      task 14, display string
lea     result,A1   address of string to display in A1
trap    #15         trap #15 performs task

move    #3,D0       task 3, display number in D1.L
trap    #15         trap #15 performs task

bsr     newLine
* Stop execution
stop    #\$2000

*------------------------------------
* Add the number in register D1 to the number in register D2.
* The sum is returned in register D1.
* D1 = D1 + D2
rts                         return

*------------------------------------
* Add two numbers passed as parameters on the stack.
* The sum is returned on the stack.
* The OFFSET directive is used to access the parameters by name.
* 4 bytes for A0 saved by link, 4 bytes for saving D0
offset  2*4
sum     ds.l    1
num2    ds.l    1
num1    ds.l    1
org     *           end the offset

move.l  D0,-(SP)        save D0
move.l  (num1,A0),D0    access num1 parameter
move.l  D0,(sum,A0)     store result in sum parameter
move.l  (SP)+,D0        restore D0
unlk    A0
rts                     return

*------------------------------------
* Subroutine to display Carriage Return and Line Feed
newLine
movem.l d0/a1,-(SP)         push d0 & a1
move    #14,d0              task number into D0
trap    #15                 display return, linefeed
movem.l (SP)+,d0/a1         restore d0 & a1
rts                         return

*------------------------------------
* Variable storage and strings
* ds (define storage) is used to reserve memory for variables
* dc (define constant) is used to place data in memory
prompt  dc.b    'Enter number: ',0  null terminated string
result  dc.b    'The sum is: ',0
crlf    dc.b    \$d,\$a,0         carriage return & line feed, null

END     START           end of program with start address specified

_________________
Prof. Kelly

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 6 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ EASy68K Forum    FAQ    Latest Features    EASy68K Questions    68000 Programming Questions    Wish List    Wishes Granted    Undocumented Features    Documented Features    General Discussion    EASy68K Projects