; SERIES.ASM ; ; Input two decimal numbers and output all integer values between those ; numbers. Original concept and dec_IO.asm I/O library by Alan Pinck. ; ; This shows how one might translate some ; Little-Man mnemonic codes (LMC) into Intel mnemonic codes. ; See: 13LMCProgramming.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. ; Students: Do NOT copy teacher-style comments into your own code. ; ; -Ian! D. Allen - idallen@idallen.ca - www.idallen.com ; November 1999, November 2009 ;---------------------------------------------------------------------- ; Both the Code Segment (CS) and Data Segment (DS) are the same. 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.asm Series ends end start ; "start" is the label on the first instruction