*************************************************************** * * * Nathan Balon * * SN# 3210 1717 * * CIS 310 * * Winter 2004 * * * * Program #2 * * The programs the total amount of money in a piggy bank. * * The results are then displayed on the screen. * * * *************************************************************** * **************************************************************** **************************************************************** * Execution Section * **************************************************************** **************************************************************** ORG $400 Program orgin BSR PRT_HEAD Display the program heading information BSR PRT_BODY Display the # of coins in the bank BSR CALC_TOT Calc the total of coin and the grand total BSR PRT_END Print the value of the coins in the banks EXIT STOP #$2700 Halt processor at end of program ***************************************************************** ***************************************************************** * Sub-routines * ***************************************************************** ***************************************************************** * * ***************************************************************** * Sub-routine PRT_TAB displays a tab. * ***************************************************************** PRT_TAB MOVE.B #TAB,D1 Display a tab MOVE.B #6,D0 TRAP #15 RTS ***************************************************************** * Sub-routine PRT_CRLF print clear linefeed and is used * * in the program to print blank lines * ***************************************************************** PRT_CRLF MOVE.B #6,D0 MOVE.B #$0D,D1 TRAP #15 MOVE.B #$0A,D1 TRAP #15 RTS **************************************************************** * Sub-routine PRT_SPS is similar to the function PRT_TAB. * * The function prints eight consecutive spaces. * * PRT_SPS is not used in the current program. I was not * * sure what the correct output for the tab should be for * * the assignment the assembler put a special symbols for * * the tab character and if the symbols were to be avoided, * * this function could be used instead. * **************************************************************** PRT_SPS CLR.L D7 MOVE.B #6,D0 MOVE.B #$20,D1 GO TRAP #15 ADD.B #1,D7 CMP #8,D7 BNE GO RTS ***************************************************************** * Sub-routine PRT_HEAD, print the heading of the program, * * including name, class, semester. ***************************************************************** PRT_HEAD MOVE.B #0,D0 Set print option LEA NAME,A1 Display my name MOVE.W #12,D1 TRAP #15 LEA CLASS,A1 Display the class MOVE.W #7,D1 TRAP #15 LEA TIME,A1 Display the class time MOVE.W #12,D1 TRAP #15 BSR PRT_CRLF Display a blank line RTS *************************************************************** * Sub-routine PRT_BODY display the body of the program, * * including the coin type and number of coins * * A2 - pointer to coin name * * A3 - pointer to # of coins * *************************************************************** PRT_BODY LEA INPUT,A1 Display the title input MOVE.W #5,D1 MOVE.B #0,D0 TRAP #15 BSR PRT_CRLF Display blank line MOVE.B #4,COUNT set counter LEA COIN_LBL,A2 Pointer to display name of coin LEA COIN_AMT,A3 Pointer to amount of coin LP CLR.L D1 MOVE.B #1,D0 Set print option BSR PRT_TAB Display a tab MOVE #1,D0 MOVEA.L A2,A1 Display the name of the coin ADDA.L #8,A2 move pointer to next coin name MOVE.W #8,D1 TRAP #15 BSR PRT_TAB Display a tab MOVE.B #0,D0 set print option CLR D1 clear data register MOVE.W (A3)+,D1 get the # of coins MOVE.B #3,D0 TRAP #15 Display # of of coins BSR PRT_CRLF Display CR/LF MOVE.B COUNT,D7 get counter values SUB.B #1,D7 decrement the counter MOVE.B D7,COUNT store counter BNE LP if counter != 0 repeat RTS *************************************************************** * Sub-routine CALC_TOT computes the total for each type * * of coin and the grand total for all coins held in the * * bank. * * A2 - face value of the coin * * A3 - # of coins in the bank * * A4 - total value of a coins * *************************************************************** CALC_TOT LEA COIN_VAL,A0 LEA COIN_AMT,A1 LEA COIN_TOT,A2 CLR D0 Loop counter LOOP CLR D1 CLR D2 coin amt MOVE.B (A0)+,D1 load the coin values MOVE.W (A1)+,D2 load the amount of coins MULU.W D2,D1 coins * value MOVE.L D1,(A2)+ store total in coin_tot array MOVE.L TOT_CENTS,D3 ADD.L D1,D3 add to grand total MOVE.L D3,TOT_CENTS store grand total ADDQ.B #1,D0 increment the counter CMP.B #4,D0 compare counter == 4 BNE LOOP if counter < 4 continue RTS *************************************************************** * Sub-routine PRT_END displays the number of dollars and * * cents that are in the bank. * * D0 - Print options D1 - string length * * D2 - total cents D3 - dollars * * D4 - cents * *************************************************************** PRT_END BSR PRT_CRLF Display a blank line MOVE.B #0,D0 set print option LEA OUTPUT,A1 Display output label MOVE.W #6,D1 TRAP #15 BSR PRT_TAB Display a tab MOVE.B #1,D0 Set print option to no CRLF LEA END0,A1 Display first end message MOVE.W #7,D1 TRAP #15 MOVE.L TOT_CENTS,D2 Get the total cents DIVU.W #100,D2 divide to get the total dollars MOVE.W D2,D3 move dollars to D3 SWAP D2 swap upper and lower words MOVE.W D2,D4 move cents to D4 MOVE.B #3,D0 set print option to number MOVE.L D3,D1 TRAP #15 Display dollars LEA END1,A1 Display second end message MOVE.W #13,D1 MOVE.B #1,D0 TRAP #15 MOVE.L D4,D1 Display cents MOVE.B #3,D0 TRAP #15 MOVE.B #0,D0 LEA END2,A1 Display the final end message MOVE.W #6,D1 TRAP #15 RTS *************************************************************** *************************************************************** ** Data Section ** *************************************************************** *************************************************************** ORG $1000 data orgin * * Labels to be printed out in the program * TAB EQU $09 ASCII tab value HEADING EQU * NAME DC.B 'Nathan Balon' my name CLASS DC.B 'CIS 310' class TIME DC.B 'Winter, 2004' semester INPUT DC.B 'Input' input label * COIN_LBL EQU * name of each coin Q_LBL DC.B 'Quarters' D_LBL DC.B 'Dimes ' N_LBL DC.B 'Nickel ' P_LBL DC.B 'Pennies ' * Output DC.B 'Output' Char Strings for result end0 DC.B 'I have ' end1 DC.B ' dollars and ' end2 DC.B ' cents.' * * Defines the values for each coin * COIN_VAL DC.B 25 value of a quarter is 25 DC.B 10 value of a dime is 10 DC.B 5 value of a nickel is 5 DC.B 1 value of a penny is 1 * * Defines storage to hold the totals * COIN_TOT DS.L 1 Array used to hold the total value DS.L 1 of each coin. DS.L 1 DS.L 1 * * Amount of each coin * COIN_AMT DC.W 175 Number of each coin held in the bank DC.W 139 DC.W 201 DC.W 1003 * * Other variables used * TOT_CENTS DS.L 1 total cents in the banks COUNT DS.B 1 counter variable END $400