EASy68K  
It is currently Wed Jun 03, 2020 2:14 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Apr 01, 2013 12:36 pm 
Offline

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
 Profile  
 
PostPosted: Mon Apr 01, 2013 2:13 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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
 Profile  
 
PostPosted: Mon Apr 01, 2013 2:21 pm 
Offline

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


Top
 Profile  
 
PostPosted: Mon Apr 01, 2013 3:35 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
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.

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Mon Apr 01, 2013 4:20 pm 
Offline

Joined: Mon Apr 01, 2013 12:32 pm
Posts: 9
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


Top
 Profile  
 
PostPosted: Mon Apr 01, 2013 7:16 pm 
Offline
User avatar

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

_________________
Prof. Kelly


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

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