Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *-----------------------------------------------------------
- * Program : Postifx
- * Written by : Conner Wingard
- * Date : 11/18/2010
- * Description: rpn calculator
- *-----------------------------------------------------------
- ORG $1000
- START: ; first instruction of program
- LEA welcome,A1
- MOVE.B #14,D0
- TRAP #15
- MOVE.B #0,D6
- MOVE.B #0,D5
- LOOP LEA message,A1
- MOVE.B #14,D0
- TRAP #15
- MOVE.B #5,D0
- TRAP #15
- CMP.B #43,D1
- BEQ PUSHOP
- CMP.B #45,D1
- BEQ PUSHOP
- CMP.B #42,D1
- BEQ PUSHOP
- CMP #64,D1 ;ascii code for @
- BEQ EVAL_2
- MOVE.B D1,-(SP)
- BRA LOOP
- PUSHOP MOVE.B D1,-(A2) ; push op to op stack
- ADD.B #1,D6 ; add to current number of operators
- BRA LOOP
- ADDFUNC CLR.B D3
- CLR.B D4
- MOVE.B (SP)+,D3 ; pop MSW word at SP to D2
- MOVE.B (SP)+,D4
- SUB #'0',D3
- SUB #'0',D4
- ADD.B D3,D4
- MOVE.B D4,-(SP)
- SUB.B #1,D6
- BRA EVAL_2
- MINFUNC CLR.B D3
- CLR.B D4
- MOVE.B (SP)+,D3 ; pop MSW word at SP to D2
- MOVE.B (SP)+,D4
- SUB #'0',D3
- SUB #'0',D4
- SUB.B D3,D4
- MOVE.B D4,-(SP)
- SUB.B #1,D6
- BRA EVAL_2
- MULFUNC CLR.B D3
- CLR.B D4
- MOVE.B (SP)+,D3 ; pop MSW word at SP to D2
- MOVE.B (SP)+,D4
- SUB #'0',D3
- SUB #'0',D4
- MULU D3,D4
- MOVE.B D4,-(SP)
- SUB.B #1,D6
- BRA EVAL_2
- EVAL_2 CLR.B D1
- CLR.B D7
- CMP.B #0,D6
- BEQ DONE
- MOVE.B (A2)+,D7
- CMP.B #43,D7
- BEQ ADDFUNC
- CMP.B #45,D7
- BEQ MINFUNC
- CMP.B #42,D7
- BEQ MULFUNC
- BRA EVAL_2
- *-------------TERMINATE---------------------------
- DONE CLR.B D1
- MOVE.B (SP)+,D1
- *SUB #'0',D1
- MOVE.B #3,D0
- TRAP #15
- LEA bye,A1
- MOVE.B #14,D0 ; say bye
- TRAP #15
- MOVE.B #9,D0
- TRAP #15 ; halt simulator
- * Variables and Strings
- CR EQU $0D ; Carriage return
- LF EQU $0A ; line feed
- Bye DC.B CR,LF,'Bye now!',0
- Message DC.B CR,LF,'Enter Expression: ',0
- END START ; last line of source
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement