It is currently Thu Apr 09, 2020 8:21 am

 All times are UTC

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: to find the sum of 10 numbersPosted: Mon Apr 01, 2013 12:36 pm

Joined: Mon Apr 01, 2013 12:32 pm
Posts: 9
Write a program that will save 10 numbers (one byte each) in the memory at address \$2000. The program then will calculate the sum of the numbers by using subroutin and save it in D5.
It will also count the number of positive numbers and save it in D6.
Beside that it will also find the number of odd numbers and save it in D7

Last edited by reem on Mon Apr 01, 2013 2:24 pm, edited 1 time in total.

Top

 Post subject: Re: to find the sum of 10 numbersPosted: Mon Apr 01, 2013 2:13 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
This is obviously a homework question. We do not solve homework questions on this forum. Approach this as you would any programming assignment.
Solve the logic first.
Create a diagram or pseudocode of the logic.
Verify the logic.
Write the code.
Test the code.
Repeat until correct.
If you have specific 68000 programming questions we will help.

_________________
Prof. Kelly

Top

 Post subject: Re: to find the sum of 10 numbersPosted: Mon Apr 01, 2013 2:21 pm

Joined: Mon Apr 01, 2013 12:32 pm
Posts: 9
ok ,, i write first code for find the sum of 10 numbers and it's work but i dont know how to write it as a subrotine
my code :
Code:
---------------------------
ORG    \$2000
dc.b   \$1,-\$1,\$1,\$1,\$1,\$4,\$1,\$1,\$1,\$2
START: clr.l d5
move.b #1,d1
move.l #\$2000,a1
move.b   (A1),D5
move.b \$1(a1),d3
move.b \$2(a1),d3
bne  loop2
move.b \$3(a1),d3
move.b \$4(a1),d3
bne  loop4
move.b \$5(a1),d3
bne  loop5
move.b \$6(a1),d3
bne  loop6
move.b \$7(a1),d3
bne  loop7
move.b \$8(a1),d3
bne  loop8
move.b \$9(a1),d3
cmp #10,d1
beq  11
bne  loop8

END    START        ; last line of source

** please can you help me to change it as asubrotine ?!!

Top

 Post subject: Re: to find the sum of 10 numbersPosted: Mon Apr 01, 2013 3:35 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
Use the code tags around code in your posts.
DO NOT post the same question in more than one place.

A subroutine is code that may be branched to and executed by name or address and then automatically returns to the calling code.

Example subroutine:
Code:
*------------------------------------
* Add the number in register D1 to the number in register D2.
* The sum is returned in register D1.
* D1 = D1 + D2
rts                         return
The label Adder1 may be used to call the subroutine. The rts instruction returns to calling code. The subroutine is called by using either the BSR or JSR instruction.
Code:
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, call the subroutine
The above code is from the tutorial4 example in the Examples folder of EASy68K.

_________________
Prof. Kelly

Top

 Post subject: Re: to find the sum of 10 numbersPosted: Mon Apr 01, 2013 4:20 pm

Joined: Mon Apr 01, 2013 12:32 pm
Posts: 9
ok thx alot ..

how can i subtract an a value of data rigester from number
example ::
if d0=3 and all numbers are 10
and i would to move the result to another register
like
d4 <--- 10-d0
d4 <-- 10-3 ,,, then d4=7
d6 <--- d4 ,, d6=7

i write this but it work in an a wrong way ,, how can i solve this ??

move.b d0,d4
sub.b (d0,#\$10),d4
move.b d4,d6

Top

 Post subject: Re: to find the sum of 10 numbersPosted: Mon Apr 01, 2013 7:16 pm

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
Code:
move.b  #10,d4
sub.b   d0,d4
move.b  d4,d6

_________________
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 [ 6 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 3 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