; SERIES.ASM
; 
; Input two numbers and output all integer values between those numbers.
; Original concept and I/O library by Alan Pinck.
;
; This shows how one might translate some
; Little-Man mnemonic codes (LMC) into Intel mnemonic codes.
;
; See: http://elearning.algonquincollege.com/coursemat/pincka/dat2343/lect054.htm
; for the original algorithm.
;
; Prompts have been added to tell the user to enter each number.
;
; The comments are the LMC codes used to implement the algorithm.
;
; -IAN! idallen@ncf.ca  November 1999
;----------------------------------------------------------------------
Series	segment
	assume	CS:Series,DS:Series
	org	100h		; .COM requires this
;----------------------------------------------------------------------
start:
	; clear the DOS screen
	;
	mov	dx,offset cls	; clears the screen: ESC [ J
	mov	ah,09h		; print ASCII$ string, pointer in DX
	int	21h

	; prompt for the first number
	;
	mov	dx,offset first
	mov	ah,09h		; print ASCII$ string, pointer in DX
	int	21h

	; * Get the first number into "small"
	; IN
	; STO small
	;
	call	getnum
	jc	error		; carry bit is set by getnum on error
	mov	small,ax	; save first number in memory

	; prompt for the second number
	;
	mov	dx,offset second
	mov	ah,09h		; print ASCII$ string, pointer in DX
	int	21h

	; * Get the second number into "big"
	; IN
	; STO big
	;
	call	getnum
	jc	error		; carry bit is set by getnum on error
	mov	big,ax		; save second number in memory

	; * Test to make sure that "small" is below "big"
	; LDA big
	; SUB small
	; SKN
	; JMP ok
	;
	mov	ax,small
	cmp	ax,big		; compare small (in AX) with big
	jbe	ok		; jump around if small <= big

	; * Ooops: small > big; must swap small and big
	; LDA small
	; STO temp
	; LDA big
	; STO small
	; LDA temp
	; STO big
	;
	mov	bx,big		; now AX=small and BX=big
	mov	big,ax		; store small into big
	mov	small,bx	; store big into small
	
ok:
	; * Increment small by one before starting loop
	; LDA small
	; ADD one
	; STO small
	;
	mov	ax,small
	add	ax,1h
	mov	small,ax

while:
	; * See if small >= big and jump out if true
	; LDA small
	; SUB big
	; SKN
	; JMP endw
	mov	ax,small
	cmp	ax,big		; compare small with big
	jae	endw		; jump out if small is above or equal

	; * Output this number
	; LDA small
	; OUT
	;
	mov	ax,small	; number must be in AX
	call	shownum		; see INCLUDE statement, below

	; * Increment small by one and retry the loop
	; ADD one
	; STO small
	; JMP while
	;
	add	ax,1h
	mov	small,ax
	jmp	while

endw:
done:
	; * We're done.  End the program:  return to DOS
	; HLT
	;
	mov	al,0h		; return 0 code in AL
	mov	ah,4Ch		; code for "terminate program"
	int	21h

	; * Error message for when getnum fails
	;
error:	mov	dx,offset errmsg
	mov	ah,09h		; print ASCII$ string, pointer in DX
	int	21h

	jmp	done
;----------------------------------------------------------------------
; Data and variables down here.
;
small	dw	?
big	dw	?
cls	db	27,'[','J'
	db	"$"
errmsg	db	"Unrecognized Input Number"
	db	"$"
first	db	"Enter first number :"
	db	"$"
second	db	"Enter second number :"
	db	"$"
;----------------------------------------------------------------------
	include	dec_IO.pkg
Series	ends
        end start               ; "start" is the label on the first instruction
