; ADDTWO.ASM ; ; A sample of how to include and call routines in the getshow.asm ; numeric I/O package, written by Alan Pinck (and modified by me). ; The modifications I made remove the extra newlines output by the ; package - you need to explicitly display newlines when you need to, ; including after reading input. (The DOS carriage return character ; is echoed; but, it isn't automatically followed by a newline.) ; ; You can test this program with input redirected from a file or ; a pipe under DOS: ; ; C:\> echo 1 2 | addtwo ; Please enter a number for the sample program: 1 ; Please enter a number for the sample program: 2 ; ; The sample program gives you an answer of: 3 ; ; Students: Do NOT copy teacher-style comments into your own code. ; ; -Ian! D. Allen - idallen@idallen.ca - www.idallen.com ; April 2000, November 2009 ; ;------------------------------------------------------------------- ; Both the Code Segment (CS) and Data Segment (DS) are the same. AddTwo segment assume CS:AddTwo,DS:AddTwo org 100h ; .COM requires this ;------------------------------------------------------------------- start: mov dx,offset prompt ; prompt for input mov ah,09h int 21h call getnum ; read input number jc error ; non-numeric? mov a,ax ; save the first number mov dx,offset newline ; put out a newline mov ah,09h int 21h mov dx,offset prompt ; prompt for more input mov ah,09h int 21h call getnum ; read input number jc error ; non-numeric? mov b,ax ; save the second number mov dx,offset newline ; put out a newline mov ah,09h int 21h mov ax,a ; need first value in a register add ax,b ; do the addition mov c,ax ; store result mov dx,offset showmsg ; display a nice message mov ah,09h int 21h mov ax,c ; display the result of the addition call shownum mov dx,offset newline ; put out a newline at the end mov ah,09h int 21h ; Quit the program (return to the O/S). ; mov al,0h ; load a successful return status goexit: mov ah,4Ch ; code for "terminate program" int 21h error: mov dx,offset errmsg ; display an error message mov ah,09h int 21h mov al,1h ; load a failure non-zero return status jmp goexit ; take the regular program exit a dw ? ; the first sample number b dw ? ; the second sample number c dw ? ; the result of the addition prompt db "Please enter a number for the sample program: " db "$" ; end of ASCII$ string showmsg db "The sample program gives you an answer of: " db "$" ; end of ASCII$ string errmsg db 0Dh,0Ah ; CR, LF db "This sample program encountered non-numeric input. Goodbye." db 0Dh,0Ah ; CR, LF db "$" ; end of ASCII$ string newline db 0Dh,0Ah ; CR, LF db "$" ; end of ASCII$ string ;------------------------------------------------------------------- INCLUDE getshow.asm ; a modified version of Alan's dec_io.pkg AddTwo ends end start ; "start" is the label on the first instruction