EASy68K  
It is currently Wed Jun 03, 2020 3:22 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Apr 22, 2013 2:00 pm 
Offline

Joined: Mon Apr 01, 2013 12:32 pm
Posts: 9
plzz help me in this ::
i have an homework and i write an code but it's doesn't work can you help me plzz:::
the homework is to let the user to enter 3 numbers and tge program will find the max and the min by using trap's ...
as this :
Enter three numbers:
4
-5
2
max: 4
min: -5

My Code ::
Code:
     org $1000

loop add #1,d6

        move.b #4,d0
         trap #15
         cmp #3,d6
         cmp d6,d4
         bgt m1
         blt less
         bne loop
         bsr endloop
endloop    rts
m1      move.l d4,d1
         lea msg1,a1
         move.b #3,d1
         trap #15
         move.b #3,d0
         trap #15
         bsr endloop
less     move.l d4,d1
         lea msg2,a1
         move.b #8,d1
         move.b #1,d0
         trap #15
         move.b #3,d0
         trap #15
         bsr endloop

start   clr.l d4
         move.b #0,d5
         move.b #0,d6
         lea msg,A1
         move.b #18,d1
         trap #15
         bsr loop
msg    dc.b 'enter 3 numbers : '
msg1    dc.b 'max'
msg2    dc.b 'min : '

            end start

[admin: added code tags]


Top
 Profile  
 
PostPosted: Mon Apr 22, 2013 2:09 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
I will not answer any questions about an assembly language program that does not contain comments.

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Mon Apr 22, 2013 2:45 pm 
Offline

Joined: Mon Apr 01, 2013 12:32 pm
Posts: 9
Code:
     org $1000

loop  add #1,d6             /// this loop to enter the 3 numbers by user
     
      move.b #4,d0
       trap #15
       cmp #3,d6
       cmp  d6,d4             
       bgt  m1                     // to move to m1 to find and print the max number
       blt  less                    // to move to less to find and print the min number
       bne loop
       bsr endloop                 // to leave the subrotine
endloop rts
m1      move.l  d4,d1           // to take the number and display it on screen when the numer is the max number out of the 3 number's
        lea msg1,a1               // msg1 >> max
        move.b #3,d1
        trap #15
        move.b #3,d0
        trap #15
        bsr endloop
less    move.l d4,d1       // to take the number and display it on screen when the numer is the min  number out of the 3 number's
        lea msg2,a1           // msg2 >> min :
        move.b #8,d1
        move.b #1,d0
        trap #15
        move.b #3,d0
        trap #15
        bsr endloop       
           
start  clr.l d4
       move.b #0,d5             
       move.b #0,d6
       lea msg,A1               // to dispaly on screen "enter 3 numbers : "
       move.b #18,d1
       trap #15
       bsr loop
msg   dc.b   'enter 3 numbers : '
msg1  dc.b   'max'
msg2  dc.b   'min   : '
        end start

[admin: added code tags]


Top
 Profile  
 
PostPosted: Mon Apr 22, 2013 3:37 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
Your code indicates a lack of understanding of how subroutines operate.

A subroutine is called with the BSR (branch to subroutine) instruction. The BSR instruction saves the return address to the stack and starts running the code in the subroutine. The subroutine concludes with the RTS (return from subroutine) instruction. The RTS instruction retrieves the saved address from the stack and returns program execution to the instruction following the BSR. The basic format would look like this:
Code:
        code
        code
        BSR   sub1
        code
    program end

sub1    code
        code
        RTS

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Mon Apr 22, 2013 7:33 pm 
Offline

Joined: Mon Apr 01, 2013 12:32 pm
Posts: 9
plzz i have try hard and i changed my code .. !
why my program be in an infinite loop ??

Code:
*-----------------------------------------------------------
* Title      :
* Written by :
* Date       :
* Description:
*-----------------------------------------------------------
    ORG    $1000

l1     add.b #1,d5    * l1 to let the user enter 3 number's then find max and mincounter
       move.b #4,d0
       trap #15
       move.b d1,d2
       cmp   d6,d2
       bgt    max
       move.b  d6,d4     * d2 < d6 ,,, d4 to save the min value
       cmp  #3,d5
       bne  l1
       bra     end   
           

smax  move.b d2,d3       *d2 > d6 ,,, d3 for the max value
      rts             
max    bsr smax          * to go to the subrotine smax to find the max
       bne l1
end    rts       

START:
       clr.l d2
       clr.l d3
       move.b #0,d5
       move.l #0,d6
       lea msg,A1
       move.b #18,d1
       trap #15
       bsr l1

       lea msg1,a1
       move.b #10,d1
       move.b #1,d0
       trap #15 
       move.b d3,d1    * d3 to save the max in it
       move.b #3,d0
       trap #15
       
       
       lea msg3,a1
       move.b #20,d1
       move.b #0,d0
       trap #15
       
       lea  msg2,a1
       move.b #10,d1
       move.b #1,d0
       trap #15
       
       move.b d4,d1     * d4 to save the min in it
       move.b #3,d0
       trap #15
       

msg   dc.b   'enter 3 numbers : '
msg1  dc.b   'the max : '
msg2  dc.b   'the min : '
msg3  dc.b   '                    '
    END    START        ; last line of source

[admin: added code tags]


Top
 Profile  
 
PostPosted: Mon Apr 22, 2013 7:58 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
Load the program into Sim68K and step through the code by pressing the "Trace Into" button on the toolbar or use the F7 key. You will see it get stuck in a loop.

_________________
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 12 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:  
cron
Powered by phpBB® Forum Software © phpBB Group