News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Loops, Arrays, and MOV function!

Started by Seed_87, July 22, 2008, 02:41:47 AM

Previous topic - Next topic

Seed_87

Okay so i'm back again! I feel i'm the only one asking  ( probably dumb ) things around here  :(

Anyway, here it is!



.data                     

                     
    cpu_numeros dd 1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13        ; this is supposed to be a deck of cards split between two
    usr_numeros  dd 1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13        ; players, so its (13x2) x2 = 52 cards

    loop_stopper   dd      ?
    aux                dd      ?


.code

mov loop_stopper,50                       ;50 "shuffles" should do

loop_start:


        call RandomNumber        ; in the end of this procedure, a random number between 0-25 is generated and stored in EDX
        mov ECX, EDX               ; because im trying to shuffle cards stored in TWO arrays, i need TWO random numbers so I save this one in ECX       
        call RandomNumber        ; this one stays in EDX


        mov aux1, [cpu_numeros+EDX]                                 ; these three lines are supposed to switch the values and "shuffle" the cards

        mov [cpu_numeros+EDX], [usr_numeros+ECX]

        mov [usr_numeros+ECX], aux1



cmp loop_stopper, 0
dec loop_stopper                 
jg loop_start                                 ; itll loop to loop_start while loop_stopper > 0





By the way, my loop is that weird and not as simple as just using the normal 'loop' because it apparently uses EDX or ECX to loop and messes with the RandomNumber procedure raymond VERY kindly let me use !  :U your code rocks (again)!

Problem is, mov is kind of "picky' when it comes to its parameters....

And it doesnt like the whole 'cpu_numeros+ECX' or 'usr_numeros+EDX' .. throwing the same error on all three mov lines in MASM9 Ver. 3.0n (latest):

Error A2070: invalid instruction operands

What am i doing wrong here?  :eek

Any help greately appreciated  :bg!!

Alex.


Neil

Here is an example of a valid instruction :-

                         mov eax, [cpu_numeros+EDX]

You can't have 2 variables in the expression.

By the way you are in the wrong forum again, your code is 32 bit  :bdg

Neil

I've just noticed the last part of your code,

         cmp loop_stopper, 0
         dec loop_stopper                 
         jg loop_start

It should be

         dec loop_stopper                 
         jne loop_start

You've got it in the wrong order & you don't  need the compare instruction as the Z flag will be set when loop_stopper reaches 0

Seed_87

Thanx a lot Neil!  :U

Im just about to apply your corrections to my code.

And, well I gotta say then I cant really distinguish 32bit code from 16 bit code because I completely thought that was 16bit  :eek

Sorry for the troubles! ( I mean moderators moving my threads from forum to forum   :dance: )

Seed_87

Okay so I changed a bit those three mov lines and now I weirdly get the same error but (  hey, i said weirdly I warned you ) ONLY in the lines marked with an *



        mov EAX,[cpu_numeros+ECX]                   ?
        mov aux1, EAX
       
        mov eax,[usr_numeros+EDX]                    *
        mov [cpu_numeros+ECX], EAX                  ?

        mov EAX, aux1
        mov [usr_numeros+EDX], EAX                  *




The lines with ?'s are pretty much exactly the same as the lines with *'s. so why do I get only two errors instead of four?  :red
I really hope i'm making sense here.. :bg  Help!

Alex.

MichaelW

The problem must be somewhere in the code that you did not post. This assembles with no errors.

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      cpu_numeros   dd 1,2,3,4,5,6,7,8,9,10
      usr_numeros   dd 1,2,3,4,5,6,7,8,9,10
      aux1          dd ?
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    mov EAX, [cpu_numeros+ECX]
    mov aux1, EAX
       
    mov eax, [usr_numeros+EDX]
    mov [cpu_numeros+ECX], EAX

    mov EAX, aux1
    mov [usr_numeros+EDX], EAX

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start

eschew obfuscation

Seed_87

Yeah it assembles, which is so weird, BUT, when you try to run it, it dies it closes and doesn't do a thing!! :eek

Which is even more weird.. try it! Please! Otherwise then theres something wrong with MASM? ( I got MASM9 v3.0n )

:( confused!!

MichaelW

The code I posted will display "Press any key to exit..." and then wait for a key press, before closing. If you did not include something similar in your code, then it will run and exit, probably so fast that even if it did display something, you would not have a chance to see it. Try posting your complete code.
eschew obfuscation

Seed_87

#8
I think i didn't use the correct words when i said "it dies, it closes and doesn't do a thing!!", im sorry :P

I meant this is whats happens when I run that code!  :eek   




In fact, the only way the code doesn't crash when i'm running it is only when i comment thise two mov lines, like this!
I guess he doesnt like it when I use [usr_numeros+EDX] ?





Im thinking theres something wrong with MASM32 then..

Sorry I just woke up and need to run to class, I will post my code here as soon as I come back!

Thanx MichaelW.  :U

jj2007

Looks like you assembled it for WINDOWS instead of CONSOLE...

Neil

asd.exe is SPYWARE & not part of MASM32

Neil

More bad news:- :(

If your computer has the asd.exe process running on it, your computer could be infected with a virus known as 'vbs.annod.b'.

asd.exe is considered to be a security risk, not only because antivirus programs flag vbs.annod.b virus as a virus, but also because a number of users have complained about its performance.

vbs.annod.b virus is likely a virus and as such, presents a serious vulnerability which should be fixed immediately! Delaying the removal of asd.exe may cause serious harm to your system and will likely cause a number of problems, such as slow performance, loss of data or leaking private information to websites.

Seed_87

Omg no! asd is just some name I gave for michaels code!

Hahaha Neil you scared me  :eek

I tend to use the letters "asd" a lot, for names of files and stuff, i didn't know it was so popular  :dance:

Im pretty sure i got no virus, but thanx anyway for your concern neil  :thumbu


By the way, I got it to work.. dont ask me how though, i guess perseverance goes a long way!  :U
Ill post the code later when i get it all organized!


Thanx to all!  :U  :U

Tedd

One problem would be that you're using registers as memory pointers without initialising them to meaningful values first.


start:

;*** ecx could be any value at this point - you're then trying to access "cpu_numeros[ECX]"
mov EAX, [cpu_numeros+ECX]        ;reading from "cpu_numeros[???]" -- not good
mov aux1, EAX

;*** edx is unknown too
mov eax, [usr_numeros+EDX]
mov [cpu_numeros+ECX], EAX        ;writing to "cpu_numeros[???]"

mov EAX, aux1
mov [usr_numeros+EDX], EAX        ;writing to "usr_numeros[???]"
No snowflake in an avalanche feels responsible.

MichaelW

Quote from: Tedd on July 23, 2008, 09:03:39 PM
One problem would be that you're using registers as memory pointers without initialising them to meaningful values first.

Yes, obviously. Thanks for the correction.
eschew obfuscation