Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 14th, 2006, 4:11 AM   #1
MacNilly
Newbie
 
Join Date: Feb 2006
Location: Sacramento, CA
Posts: 4
Rep Power: 0 MacNilly is on a distinguished road
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
MacNilly is offline   Reply With Quote
Old Feb 14th, 2006, 8:04 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It's been a long time since I've used this; should you be setting BH to zero before calling that last PUTDEC$? I have no ideas regarding CodeView.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 15th, 2006, 1:16 AM   #3
MacNilly
Newbie
 
Join Date: Feb 2006
Location: Sacramento, CA
Posts: 4
Rep Power: 0 MacNilly is on a distinguished road
Tried that but same result. Also I tried changing the first 2 lines of the .CODE segment to
MOV AX, @DATA
MOV ES, AX
Because I didn't know what in the world "SEG DGROUP" was. Also I removed the line "DOSSEG" from just above the .STACK definition and the output was "Numbers in this series: ~1024." Also the only command that alters CNT is "INC CNT" so that's not the problem. Also, any number greater than 500 crashes the program with a Windows 16 Bit DOS Subsystem fault.
/sigh
MacNilly is offline   Reply With Quote
Old Feb 15th, 2006, 3:38 AM   #4
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
I just tried this in inline (C++) assembly (minus the input and output routines) and it seemed to work OK. Note that this was in a 32 bit compiler, so it may not show anything.
Are you sure PUTDEC$ and NEWLINE don't do anything nasty like change the value of AX? That would muck up your program pretty well.
The Dark is offline   Reply With Quote
Old Feb 15th, 2006, 5:56 AM   #5
MacNilly
Newbie
 
Join Date: Feb 2006
Location: Sacramento, CA
Posts: 4
Rep Power: 0 MacNilly is on a distinguished road
Yeah mostly got it working now. It works for all the test numbers my instructor gave us except for one number where it just infinite loops and outputs 0's.
MacNilly is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC