EASy68K  
It is currently Tue Apr 25, 2017 12:36 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: New in Assembly
PostPosted: Tue May 14, 2013 1:07 am 
Offline

Joined: Tue May 14, 2013 12:51 am
Posts: 2
I am really new to assembly programming. I always work with java and wanted to learn more. Is there anyone that can give me an example for Fibonacci and lowercase to uppercase programs ? Because I think those 2 programs will have all the codes that will help me around. Thank you in advance!


Top
 Profile  
 
 Post subject: Re: New in Assembly
PostPosted: Sat May 18, 2013 12:41 am 
Offline

Joined: Tue May 14, 2013 12:51 am
Posts: 2
This is the 1st program I wrote. The greatest number out of 3 numbers. But my 3rd input seems to not work only 1st one and 2nd one, whenever I try my 3rd one to have the highest input the output comes out as the 2nd one. Can anyone help me ?
------------------------------------------------------------------------------------------------------------------------------------------
Code:
 ORG    $1000               
START:                ; first instruction of program
    MOVE.B    #6,D1
**************************************************************
StartDisplay
    MOVE.B    #14,d0        ;Display instructions
    LEA    instrMsg1,a1
    TRAP    #15
   
    MOVE    #4,D0        ; Enter first number
    TRAP    #15
   
    MOVE.B    D1,D7
**************************************************************
StartDisplay2
    MOVE.B    #14,d0       
    LEA    instrMsg2,a1
    TRAP    #15
   
    MOVE    #4,D0        ; Enter second number
    TRAP    #15

    MOVE.B    D1,D6
**************************************************************
StartDisplay3
    MOVE.B    #14,d0       
    LEA    instrMsg3,a1
    TRAP    #15
   
    MOVE    #4,D0        ; Enter third number
    TRAP    #15

    MOVE.B    D1,D5
   
*1st Number = D7
*2nd Number = D6
*3rd Number = D5
**************************************************************
Logic
    MOVE.B    D7,D2
    MOVE.B    D6,D3
    MOVE.B    D5,D4

    SUBX.B    D7,D6    Subtracted value is in D6   
    BLT    Loop1    ;D7>D6
    BGT    Loop2    ;D6>D7
   
**************************************************************   
Loop1
    MOVE.B    #14,D0    ;Display D7>D6
    LEA    Msg,A1
    TRAP    #15

    MOVE     D2,D1
    MOVE.B    #3,D0
    TRAP    #15
   
    BGT    HALT
   
    MOVE.B    D2,D7   
    MOVE.B    D5,D4   

    SUBX.B    D2,D4
    BGT    Loop4    ;D5 is Greatest
    BLT    Loop3    ;D7 is Greatest
**************************************************************
Loop2
    MOVE.B    #14,D0    ;Display D6>D7
    LEA    Msg,A1
    TRAP    #15
   
    MOVE     D3,D1
    MOVE.B    #3,D0
    TRAP    #15
   
    BGT    HALT
   
    MOVE.B    D3,D6   
    MOVE.B    D4,D5   

    SUBX.B    D3,D4
    BGT    Loop4    D6>D5   
    BLT    Loop5    D5>D6
**************************************************************
Loop3
    MOVE.B    #14,D0        ;Display 1st number as Greatest
    LEA    Msg,A1
    TRAP    #15
   
    MOVE     D7,D1
    MOVE.B    #3,D0
    TRAP    #15
   
    BGT    HALT
**************************************************************
Loop4
    MOVE.B    #14,D0        ;Display 2nd as Greatest
    LEA    Msg,A1
    TRAP    #15
   
    MOVE     D3,D1
    MOVE.B    #3,D0
    TRAP    #15
   
    BGT    HALT
**************************************************************
Loop5   
    MOVE.B    #14,D0        ;Display 3rd as Greatest
    LEA    Msg,A1
    TRAP    #15
   
    MOVE     D5,D1       
    MOVE.B    #3,D0
    TRAP    #15
   
    BGT    HALT
**************************************************************
HALT    MOVE.B    #9,D0
    TRAP    #15        ; halt simulator

* Variables and Strings

crlf    dc.b    $d,$a,0    carriage return & line feed, null

newLine    movem.l    d0/a1,-(a7)    push d0 & a1
    move    #14,d0    task number into D0
    lea    crlf,a1    address of string
    trap    #15    display return, linefeed
    movem.l    (a7)+,d0/a1    restore d0 & a1
    rts        return
   
CR    EQU    $0D
LF    EQU    $0A

instrMsg1   
    DC.B    CR,LF
    Dc.B    '----- Greatest Number out of 3 Number -----',CR,LF
    DC.B    '',CR,LF
    DC.B    '      Enter your 1st number:',CR,LF,0
   
instrMsg2   
    DC.B    CR,LF
    DC.B    '     Enter your 2nd number:',CR,LF,0   

instrMsg3   
    DC.B    CR,LF
    DC.B    '     Enter your 3rd number:',CR,LF,0   
   
Msg       
    DC.B    CR,LF
    DC.B    '    The greatest number is: ',CR,LF,0

    END    START        ; last line of source


Top
 Profile  
 
 Post subject: Re: New in Assembly
PostPosted: Sun May 19, 2013 9:25 pm 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Your code never does anything but compare the first and second values entered.

If the first is greater than the second it displays the first and then quits.

If the second is greater than the first it displays the second and then quits.

If the first is equal to the second it displays the first and then quits.

If you stop execution at Logic you can step through the code and watch this happen.

Lee.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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