EASy68K  
It is currently Thu Apr 02, 2020 1:30 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon May 13, 2013 6:44 am 
Offline

Joined: Thu May 02, 2013 8:25 am
Posts: 4
While I create a simple calculator,
I faced a syntax error in this stage.(printresult)
Any suggestions that I can make it work clearly???


Code:
  org     $1000     ;code space
    move.l    #$7ffe,sp ;initialises stack pointer
    move.l     #instring,a6 ;initialise string pointer
    move.b     #0,d1     ;turn off automatic keyboard echo
    move.b     #12,d0
    trap     #15
   
*prompt to ask user for input

inrslt    move.l    #string,a3 ;initialises string
next     move.b     (a3),d1 ;get character from string
    beq     exit     ;terminate when there is a 'null' value
      add.l     #1,a3     ;increment a3 to point to next char
    move.b     #6,d0     ;OUTCH
      trap     #15     ;display the character
    bra     next     ;loop until 'null' character
exit    move.b     #9,d0     ;EXIT
   
   
*User to input response   
*First Int
    move.b     #5,d0     ;INCH
    trap     #15     ;display the character
    move.b     #6,d0     ;OUTCH
    trap     #15     ;display the character
    sub.b     #$30,d1    ;convert it from ascii
    move.b    d1, d2    ;save the first Int to d2


*Branch to quit if user enters in 'q'
    cmp.b    #$71,d2    ;comparing hex d1 w/ d2
    sub.b     #$30,d1    ;convert it from ascii
    bge    quit    ;quits out if user enters 'q'             
            ;else move to Operator
   
*Operator   
    move.b     #5,d0     ;INCH
    trap     #15     ;display the character
    move.l    d1, d3    ;save the second character
   
    move.b     #6,d0     ;OUTCH
    trap     #15     ;printing the Operator
   
*Second Int
    move.b     #5,d0     ;INCH
    trap     #15     ;display the character
    move.b     #6,d0     ;OUTCH
    trap     #15    ;display the character
    sub.b     #$30,d1    ;convert it from ascii
    move.l    d1,d4    ;save the second Int to d4
    move.b     #6,d0     ;OUTCH
    trap     #15     ;display the character

*Got all the arguments

    cmp.b     #$2B,d3 ; '+' symbol
    beq    addUp

    cmp.b    #$2D,d3    ; '-' symbol
    beq    subtract

    cmp.b    #$2A,d3    ; '*' symbol
    beq    multiply
   
    cmp.b    #$2F,d3    ; '/' symbol
    beq    divide     

    bra     unknownOp
   
   
addUp    add.b     d2,d4    ;adding the first Int to second Int in location d4
    sub.b     #$30,d1    ;convert it from ascii
    bra     display    ;branching to display

subtract sub.b    d4,d2    ;subtracting Int in location d4
    move.b    d2,d4
    bra     display    ;branching to display
   
multiply mulu.w    d2,d4       
    bra    display
   
divide    divu.w    d2,d4
    sub.b     #$30,d1    ;convert it from ascii
    bra    display
   
unknownOp
    move.b    #$15,d4    ; Display E 45-30
    bra     display
   
   
   
display    * First is adding in a CR & LF. Loop to print out 'Result is: ' & printing the result

    move.b     #$0D,d1    ;
    move.b  #6, d0    ;
    trap    #15    ;executes a CR
    move.b     #$0A,d1    ;
    move.b  #6, d0    ;
    trap    #15    ;executes a LF
   
    *'Result is: '
    move.l    #printresult,a4;
loopin     move.b     (a4),d1    ;get character from string
    beq     loopout    ;terminate when there is a 'null' value
      add.l     #1,a4     ;increment a4 to point to next char
    move.b     #6,d0     ;OUTCH
      trap     #15     ;display the character
    bra     loopin     ;loop until 'null' character
loopout    move.b     #9,d0     ;EXIT


    *Adding in the result
    add.b     #$30,d4       
    move.b     d4,d1    ;moves total from d4 to d1, to allow printing
    move.b     #6,d0     ;OUTCH
    trap     #15    ;display the character
   
    *Adding a CR & LF
    move.b     #$0D,d1    ;
    move.b  #6, d0    ;
    trap    #15    ;executes a CR
    move.b     #$0A,d1    ;
    move.b  #6, d0    ;
    trap    #15    ;executes a LF
   
    bra    inrslt    ;loop back to next until user enters 'q'

   
quit    move.b     #9,d0     ;EXIT
    trap     #15     ;display the character

   
   
data        org     $2000     ;data space
string         dc.b     'Input equation: ',lf,cr,null
printresult    dc.b    'Result is: ',null                       
lf         equ     $0a     ;defined a line feed
cr         equ     $0d     ;defined a carriage return   
null        equ     00     ;defined a null
instring     ds.w     1000     ;space 100 characters
        end     $1000
{Admin: Added code tag}


Top
 Profile  
 
PostPosted: Mon May 13, 2013 12:26 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1118
The comment field must be separated from the operand field by at least one white space.
    move.l #printresult,a4;
should be:
    move.l #printresult,a4 ;

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Tue May 14, 2013 1:31 am 
Offline

Joined: Thu May 02, 2013 8:25 am
Posts: 4
why the imput value occur twice instead once??


Top
 Profile  
 
PostPosted: Tue May 14, 2013 1:46 am 
Offline

Joined: Thu May 02, 2013 8:25 am
Posts: 4
thanks for the correction.
is it possibly asking to make this source works properly?


Top
 Profile  
 
PostPosted: Mon May 27, 2013 11:15 pm 
Offline

Joined: Wed Apr 25, 2012 12:43 pm
Posts: 6
With the correction, It works properly. It can operate with one digit numbers and also one digit in result


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

All times are UTC


Who is online

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