Re: The prodigal son returns...more easy Homework Help...



On Tue, 20 Nov 2007 21:40:34 +0100, Frank Kotler <fbkotler@xxxxxxxxxxx> wrote:

kuroikaze@xxxxxxxxx wrote:
; Find Prime Numbers and output file

To prove that flattery will get you everywhere, and that you *can* sometimes find the bug by looking at the source, I offer this preliminary observation...

(only really just started looking at this. *if* my ambition holds up, I'll have more to say...)

...
pNumsUp WORD pNumsUpMax DUP (?)
pNumsDown WORD pNumsDwnMax DUP (?)

You then go on to *use* these as DWORD arrays!!! (mov [ebx], eax and its opposite. Looking at your output, you're obviously "running off the end" of the "lower" array, and printing one number from the "higher" array. Changing these to DWORD would fix that symptom, but may not account for "all those zeros". Start with that...

...
; pop dx

They're currently commented out, but in 32-bit code, you want to push and pop full 32-bit registers.

Just wanted to add that in general it is ok
to push and pop 16 bit values as long as the stack remain aligned
afterwards

push D$eax ;push 32 bit
pop bx ;two pops to 16 bits registers
pop cx

is ok for instance. and variants are ok.

the point is that ESP is aligned _afterwards_.
No matter the method used to manipulate it.

Doing 16-bit registers will give you a badly aligned stack, or worse. There may be other places where you want to change from 16-bit registers to 32-bit registers, as well. It "sounds logical" that 16-bit calculations would be faster and "easier for the CPU". Not so (usually). The CPU works best on "native word size" - 32 bits, in this case.

; cmp dh, 1

8-bit registers are fine...

Fix the size of those arrays, and see if it helps.

Later,
Frank

P.S. I agree with the folks who say you should learn to use a debugger (and I agree with you that the results are somewhat cryptic until you figure out what you're looking at). You mentioned Windbg... Ollydbg is another "popular" one (maybe "better"?). But Masm outputs symbolic debug information in a format for Codeview - if you've got that, or can "obtain" it, that might be a good one to look at. too.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
.



Relevant Pages

  • Re: my assembler is better than your assembler
    ... pushed onto the stack by EBP will be in memory that is cached. ... but the fish may start smelling with the first PUSH. ... but only registers which are needed. ... your aspect of maintainability] ...
    (alt.lang.asm)
  • Re: Queue question wih dyn mem alloc
    ... I wrote two functions to pusha character array onto an array and ... the push function seems to work well but i have ...   carrying character arrays. ... Did you mean to use curlen-1 here? ...
    (comp.lang.c)
  • Re: Need Help Declaring a Pointer to an Array of Structures
    ... the OP defined a structure that maps onto a hardware ... of such registers, on a machine that has memory-mapped hardware ... it is just a plain old "pointer to char". ... points to an array -- or more precisely, ...
    (comp.lang.c)
  • Re: Queue question wih dyn mem alloc
    ... I wrote two functions to pusha character array onto an array and ... the push function seems to work well but i have ...   carrying character arrays. ... that's what i thought as well but if I make curlen-1 i always ...
    (comp.lang.c)
  • Re: Passing parameters & return value on the stack
    ... push arg_1 ... call someFunction ... don't save and restore the registers with pushf/pusha and popf/popa ...
    (alt.lang.asm)