Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *-----------------------------------------------------------
  2. * Program    :  Postifx
  3. * Written by :  Conner Wingard
  4. * Date       :  11/18/2010
  5. * Description:  rpn calculator
  6. *-----------------------------------------------------------
  7.     ORG $1000
  8.  
  9.  
  10. START:              ; first instruction of program
  11.  
  12.  
  13.     LEA welcome,A1
  14.     MOVE.B  #14,D0
  15.     TRAP    #15
  16.     MOVE.B  #0,D6
  17.     MOVE.B  #0,D5  
  18.    
  19.        
  20. LOOP    LEA message,A1
  21.     MOVE.B  #14,D0
  22.     TRAP    #15
  23.    
  24.     MOVE.B  #5,D0
  25.     TRAP    #15
  26.     CMP.B   #43,D1
  27.     BEQ PUSHOP
  28.     CMP.B   #45,D1
  29.     BEQ PUSHOP
  30.     CMP.B   #42,D1
  31.     BEQ PUSHOP
  32.     CMP #64,D1  ;ascii code for @
  33.     BEQ EVAL_2
  34.    
  35.     MOVE.B  D1,-(SP)
  36.     BRA LOOP
  37.    
  38. PUSHOP  MOVE.B  D1,-(A2)    ; push op to op stack
  39.     ADD.B   #1,D6   ; add to current number of operators
  40.     BRA LOOP
  41. ADDFUNC CLR.B   D3
  42.     CLR.B   D4
  43.    
  44.     MOVE.B  (SP)+,D3  ; pop MSW word at SP to D2
  45.     MOVE.B  (SP)+,D4
  46.    
  47.     SUB     #'0',D3
  48.     SUB #'0',D4
  49.    
  50.     ADD.B   D3,D4
  51.     MOVE.B  D4,-(SP)
  52.     SUB.B   #1,D6
  53.    
  54.     BRA EVAL_2
  55.  
  56. MINFUNC CLR.B   D3
  57.     CLR.B   D4
  58.    
  59.     MOVE.B  (SP)+,D3  ; pop MSW word at SP to D2
  60.     MOVE.B  (SP)+,D4
  61.     SUB     #'0',D3
  62.     SUB #'0',D4
  63.    
  64.     SUB.B   D3,D4
  65.     MOVE.B  D4,-(SP)
  66.     SUB.B   #1,D6
  67.    
  68.     BRA EVAL_2
  69.  
  70. MULFUNC CLR.B   D3
  71.     CLR.B   D4
  72.    
  73.     MOVE.B  (SP)+,D3  ; pop MSW word at SP to D2
  74.     MOVE.B  (SP)+,D4
  75.     SUB     #'0',D3
  76.     SUB #'0',D4
  77.    
  78.     MULU    D3,D4  
  79.     MOVE.B  D4,-(SP)
  80.     SUB.B   #1,D6
  81.    
  82.     BRA EVAL_2
  83.        
  84. EVAL_2  CLR.B   D1
  85.     CLR.B   D7
  86.     CMP.B   #0,D6
  87.     BEQ DONE
  88.    
  89.    
  90.     MOVE.B  (A2)+,D7
  91.     CMP.B   #43,D7
  92.     BEQ ADDFUNC
  93.     CMP.B   #45,D7
  94.     BEQ MINFUNC
  95.     CMP.B   #42,D7
  96.     BEQ MULFUNC
  97.    
  98.     BRA EVAL_2
  99.    
  100. *-------------TERMINATE---------------------------
  101. DONE    CLR.B   D1
  102.     MOVE.B  (SP)+,D1
  103.     *SUB    #'0',D1
  104.     MOVE.B  #3,D0
  105.     TRAP    #15
  106.    
  107.     LEA bye,A1
  108.     MOVE.B  #14,D0 ; say bye
  109.     TRAP    #15
  110.    
  111.     MOVE.B  #9,D0
  112.     TRAP    #15     ; halt simulator
  113.        
  114. * Variables and Strings
  115.  
  116. CR  EQU $0D     ; Carriage return
  117. LF  EQU $0A     ; line feed
  118. Bye DC.B    CR,LF,'Bye now!',0
  119. Message DC.B    CR,LF,'Enter Expression: ',0
  120.  
  121.  
  122.     END START       ; last line of source
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement