;================================================================================== ;File :ulum.asm ;Author :Andre Long ;Due :Febuary 27, 2006 ;Description :Generate a sequence of numbers via Ulim's Conjecture ;================================================================================== ;External Procedures INCLUDE Pcmac.inc EXTRN NEWLINE: FAR ;Display Newline EXTRN GETDEC$: FAR ;Gets 16-Bit Decimal Unsigned EXTRN PUTDEC$: FAR ;Display 16-Bit Decimal Unsigned EXTRN PUTSTRNG:FAR ;Display Character String ;================================================================================== .MODEL SMALL .586 .STACK 100h .DATA Welcome DB "Welcome to Ulum's World ", 13, 10, '$' getInput DB "Enter a positive whole number: ", '$' outPut DB "Ulum's sequence is : ", 13, 10, '$' messError DB " Overflow Occured! ", 13, 10, '$' counter DW 0 messInput DB "The number you entered is: ", '$' messEven DB 13, 10, "Even number ", '$' messOdd DB 13, 10, "Odd number ", '$' messCount DB " Counter= ", '$' space DB " ",'$' messSequen DB "The number sequence is: ",13, 10, '$' lineNumber DW 1 ;================================================================================== .CODE main proc _Begin ;Macro for boiler plate sPutStr Welcome ;Safe version of putstr call Newline green: sPutStr getInput call GETDEC$ ;Gets value from keyboard & stores in AX sPutStr messInput mov bh, 0 ;Display mode for 'PUTDEC' (no blanks) call PUTDEC$ ;Display AX register (unsigned) call Newline sPutStr messSequen ntest: push ax ;Save a copy of AX on the stack mov bx, 2 mov dx, 0 div bx ;Ax = Dx:Ax / bx cmp dx, 0 ;dx is where remainder is stored pop ax ;Restore Ax je nEven jmp nOdd nEven: ;sPutStr messEven ;For testing / debugging mov dx, 0 ;Make sure 'dx' is not garbage mov bx, 2 div bx ;Ax = Dx:Ax / bx add counter,1 mov bh, 1 call PUTDEC$ ;Display value X/2 sPutStr space add lineNumber, 1 cmp lineNumber, 10 ja ptX jmp ptY ptX: call Newline mov lineNumber, 1 ptY: mov cx, counter push ax mov ax, cx pop ax cmp ax, 1 ja ntest jmp exit nOdd: ;sPutStr messOdd ;For testing / debugging mov bx, 3 mul bx ;Ax = Ax*bl (bl=3) jo messO mov bx, 1 add ax, bx ;Ax = Ax + bx (bx=1) jc messO jo messO add counter,1 mov bh, 1 call PUTDEC$ ;Display value (X*3)+1 sPutStr space add lineNumber, 1 cmp lineNumber, 10 ja ptXX jmp ptYY ptXX: call Newline mov lineNumber, 1 ptYY: mov cx, counter push ax mov ax, cx pop ax cmp ax, 1 ja ntest jmp exit messO: sPutStr messError exit: call Newline sPutStr messCount mov ax, cx call PUTDEC$ mov ah, 4ch ;Exit back to DOS int 21h main ENDP END main