strange result in assembly?

In this forum members can discuss topics about specific programming languages.
Post Reply
whakamaru
Posts: 47
Joined: Thu May 06, 2010 10:08 pm

strange result in assembly?

Post by whakamaru »

MS-debug is the only language I have access to. But it does work, even if it takes ages to iron out. #303 took 13 months, #206 about one. But what about #67? My program works perfectly when run within "debug", press g= go. correct answer is displayed and "program terminated normally" appears.
But when I run it from the C: prompt, I get a wrong answer? If I run it again, the same wrong answer, but if I then go back to the desktop and return to the command window and try again... I get a different, but still wrong, answer.
What might be going on? What changes when I come back? The PC is an Asus EeeBox PC, B202, running Inter Atom N270 cpu.
I have posted the fully annotated listing on the #67 problem forum, page 9.
Two other programs don't go properly either, #16 and #20 which are similar in logic.

User avatar
jaap
Posts: 550
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: strange result in assembly?

Post by jaap »

It sounds to me as if you may be using an uninitialised value, i.e. reading from a register or memory address that has not been previously written to by your program. This can easily happen by accident if you write a 32-bit value but read a 64-bit value.

whakamaru
Posts: 47
Joined: Thu May 06, 2010 10:08 pm

Re: strange result in assembly?

Post by whakamaru »

That would explain part of what is happening. I suppose that the machine code value for "lodsw" is the same for 16-bit as it is for 32-bit. It is grabbing two numbers instead of one.
But what about the different results when returning from somewhere else?
I have since downloaded the flat-assembler programs, but don't know how to get it to work... yet.
New systems are now 64-bit, does that mean 32-bit programs might not work properly?

thundre
Posts: 356
Joined: Sun Mar 27, 2011 9:01 am

Re: strange result in assembly?

Post by thundre »

whakamaru wrote:New systems are now 64-bit, does that mean 32-bit programs might not work properly?
The 64-bit CPU manufacturers are committed to supporting the specifications, but not necessarily the exact behavior of the 32-bit systems.

This type of bug is why most people use high-level langages. Modern compilers will use variable storage consistently and either warn you about an uninitialized value or silently initialize it to zero.
Image

whakamaru
Posts: 47
Joined: Thu May 06, 2010 10:08 pm

Re: strange result in assembly?

Post by whakamaru »

Solved. I had assumed that writing data to memory would over-write anything already there. It seems not. So I erased the memory before loading the triangle numbers. Now it goes OK, so I'll be doing that again next time.

Post Reply