|
Newbie
Join Date: Feb 2006
Location: Sacramento, CA
Posts: 4
Rep Power: 0 
|
Problem with Ulong's Conjecture Program
Hello all,
I am having a problem with my program that does Ulong's Conjecture. If you don't know what that is, it's pretty simple and the code explains what I'm doing. I got it to display the right numbers, but when I get to the end I am supposed to tell how many numbers were in the series. I ran through it with CodeView and I'm still lost because I can't get codeview to watch variables (they always stay at 0). Basically I'm just getting a junk value always around ~400. Please help me understand why my program is not counting right. And also if anyone knows why CodeView won't let me watch variables.
;=============================================================================
; Ulong's Conjecture Program
; Starting with any number,
; if the number is even divide it by 2
; if the number is odd multiply it by 3 and add 1
; Stop when you get to number 1
;=============================================================================
EXTRN GETDEC$:FAR
EXTRN NEWLINE:FAR
EXTRN PUTDEC$:FAR
EXTRN PUTSTRNG:FAR
;=============================================================================
DOSSEG
.MODEL SMALL
;=============================================================================
.STACK 256
;=============================================================================
.DATA
NUM DW ?
CNT DW 0
PROMPT DB 'Enter a positive integer: '
OUTPUT DB 'Numbers in this series: '
;=============================================================================
.CODE
ULONGS PROC
MOV AX, SEG DGROUP
MOV ES, AX
LEA DI, PROMPT
MOV CX, 26
CALL PUTSTRNG
CALL GETDEC$
MOV NUM, AX
DO_NEXT: MOV AX, NUM
INC CNT
MOV BH, 0
CALL PUTDEC$
CALL NEWLINE
CMP AX, 1
JE DONE
SUB DX, DX
MOV BX, 2
DIV BX
CMP DX, 0
JNE IS_ODD
IS_EVEN: MOV NUM, AX
JMP DO_NEXT
IS_ODD: MOV AX, NUM
MOV BX, 3
MUL BX
MOV NUM, AX
INC NUM
JMP DO_NEXT
DONE:
LEA DI, OUTPUT
MOV CX, 24
CALL PUTSTRNG
MOV AX, CNT
CALL PUTDEC$
.EXIT
ULONGS ENDP
END ULONGS
|