; ######################################################################################### ; # Indiana University # ; # Computer Science Department # ; # # ; # Example Program 3 # ; # # ; # DESCRIPTION: # ; # # ; # This is a simple program to get two 2-digit decimal numbers from the terminal, # ; # convert the numbers from ASCII to decimal, add the numbers, convert the result from # ; # decimal to ASCII, and display the result on the terminal. # ; # # ; # AUTHOR: # ; # Bryce Himebaugh (bhimebau@cs.indiana.edu) # ; # IUCS Staff # ; # 6/21/99 # ; # # ; ######################################################################################### XREF STKTOP,Send_String,Get_Number,Output_Result SECTION code START: move.l #STKTOP,sp ; setup the stack pointer movem d2,-(sp) ; save the entry value of d2 on the stack clr.l d2 ; clear d2 to store the result of the calc. lea clear_screen_string,a0 ; place the starting address of string in a0 jsr Send_String ; send the string to the terminal lea position_cursor,a0 ; place the starting address of string in a0 jsr Send_String ; send the string to the terminal lea banner,a0 ; place the starting address of string in a0 jsr Send_String ; send the string to the terminal lea prompt1,a0 ; place the starting address of string in a0 jsr Send_String ; send the string to the terminal jsr Get_Number ; go get the first number from the terminal move.b d0,d2 ; save the number received in D2. lea add_symbol,a0 ; place the starting address of string in a0 jsr Send_String ; send the string to the terminal lea prompt2,a0 ; place the starting address of string in a0 jsr Send_String ; send the string to the terminal jsr Get_Number ; go get the second number from the terminal add.b d0,d2 ; add the second number to the first lea calc_bar,a0 ; place the starting address of string in a0 jsr Send_String ; send the string to the terminal lea prompt3,a0 ; place the starting address of string in a0 jsr Send_String ; send the prompt move.b d2,d0 ; place result in d0 to send it to the term jsr Output_Result ; send the result to the terminal movem (sp)+,d2 ; restore the original value of d2 clr.b d1 ; prepare to use TRAP #15 to end the program trap #15 ; execute program termination SECTION data clear_screen_string: dc.b "\x1b[2J\x00" ; String required by terminal to clear the screen position_cursor: dc.b "\x1b[1;1f\x00" ; String required by terminal to position the cursor @ 1,1 ; where the screen is row;col ; Upper left corner 1, 1 ; Lower right corner 24,80 add_symbol: dc.b "\n\r +\n\r\x00" calc_bar: dc.b "\n\r --\n\r\x00" banner: dc.b "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\r" dc.b "% This is a small program that adds two 2-digit decimal numbers. %\n\r" dc.b "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\r\n\r\x00" prompt1: dc.b " First 2-Digit Number -> \x00" prompt2: dc.b "Second 2-Digit Number -> \x00" prompt3: dc.b " Result -> \x00"