News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

After init values in array, I get nonsense when diplaying them

Started by valentin68, November 14, 2017, 12:14:06 AM

Previous topic - Next topic

valentin68

Hello. I'm not a student, but a tutor. I'm a physicist not a programmer, but 30 years ago I have written by myself the code of CelticLegends game in M68000.
So I'm very good at M68000 but do not know X86. This is my first time doing an X86 program and I find it very difficult to use the MASM32, and this assembbly language. So please help me with the following. i am writing 10 integer values in an array of integers, then I am trying to display them.

  .data
        integer dword 100 DUP(0)  ; 100 integers

; init values in integer with values from 0 to 9

            mov  ecx,0      ;index in integer array
            mov  ebx, 10   ;loop counter           
            xor  eax, eax   ; clear eax
           
init:
            mov  integer[ecx*2], eax
           
            push eax
            push ebx
            push ecx
            print str$(integer[ecx*2]), 10,13
            pop ecx
            pop ebx
            pop eax
           
            inc  eax
            inc  ecx
            dec  ebx
            cmp  ebx,0
            jnz  init

;start displaying values
            mov  ecx,0      ;index in integer array
            mov  ebx, 10   ;loop counter           
            xor  eax, eax   ; clear eax
           
display:
                       
            push eax
            push ebx
            push ecx
            print str$(integer[ecx*2]), 10,13
            pop ecx
            pop ebx
            pop eax
           
            inc  eax
            inc  ecx
            dec  ebx
            cmp  ebx,0
            jnz  display

AThe first print in the init prints good numbers from 0 to 9
The second print in the display prints random numbers 65536, 131073, ...etc

where I am mistaing please? I read yesterday that a print modify the registers, thus I am pushing and pop them, but the display does not do what is has to do.
Please help.

aw27

Valentin,

Replace all instances of ecx*2 with ecx*4 and you will be probably good (untested).

valentin68

Quote from: aw27 on November 14, 2017, 12:49:50 AM
Valentin,

Replace all instances of ecx*2 with ecx*4 and you will be probably good (untested).

Yes, it worked
I had  dd declarations for double word, and I was thinking that dword is stored on 2 bytes, it was stored on 4 bytes instead.