![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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 |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2006
Location: Sacramento, CA
Posts: 4
Rep Power: 0
![]() |
Tried that but same result. Also I tried changing the first 2 lines of the .CODE segment to
MOV AX, @DATA MOV ES, AX /sigh |
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 810
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Feb 2006
Location: Sacramento, CA
Posts: 4
Rep Power: 0
![]() |
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.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|