EASy68K
http://www.easy68k.com/EASy68Kforum/

to find the sum of 10 numbers
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1182
Page 1 of 1

Author:  reem [ Mon Apr 01, 2013 12:36 pm ]
Post subject:  to find the sum of 10 numbers

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

Author:  profkelly [ Mon Apr 01, 2013 2:13 pm ]
Post subject:  Re: to find the sum of 10 numbers

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.

Author:  reem [ Mon Apr 01, 2013 2:21 pm ]
Post subject:  Re: to find the sum of 10 numbers

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
loop   add.b #1,d1
       add.b d3,d5
       move.b $2(a1),d3
       bne  loop2
loop2  add.b #1,d1
       add.b d3,d5
       move.b $3(a1),d3
loop3   add.b #1,d1
       add.b d3,d5
       move.b $4(a1),d3
       bne  loop4
loop4   add.b #1,d1
       add.b d3,d5
       move.b $5(a1),d3
       bne  loop5
loop5   add.b #1,d1
       add.b d3,d5
       move.b $6(a1),d3
       bne  loop6
loop6  add.b #1,d1
       add.b d3,d5
       move.b $7(a1),d3
       bne  loop7
loop7   add.b #1,d1
       add.b d3,d5
       move.b $8(a1),d3
       bne  loop8
loop8   add.b #1,d1
       add.b d3,d5
       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 ?!!

Author:  profkelly [ Mon Apr 01, 2013 3:35 pm ]
Post subject:  Re: to find the sum of 10 numbers

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
Adder1
    add.l   d2,d1
    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

    * Input 2 numbers and add them with Adder1 subroutine.
    * 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
    trap    #15         perform task
    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.

Author:  reem [ Mon Apr 01, 2013 4:20 pm ]
Post subject:  Re: to find the sum of 10 numbers

ok thx alot ..

please another qustion :
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

Author:  profkelly [ Mon Apr 01, 2013 7:16 pm ]
Post subject:  Re: to find the sum of 10 numbers

Code:
    move.b  #10,d4
    sub.b   d0,d4
    move.b  d4,d6

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/