News:

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

Main Menu

registers as pointer q

Started by dc, September 08, 2023, 04:00:09 AM

Previous topic - Next topic

HSE

Quote from: dc on September 25, 2023, 08:24:34 AMbt [eax+esi],0
i get errors in assembly

You must indicate to assembler what have to retrieve in memory position:

bt word ptr [eax+esi],0

bt dword ptr [eax+esi],0

Always is the same in any instruccion when first you have a memory position.

You don't need to make any indication when first there is a known size operand:

mov al, [eax+esi]

mov ax, [eax+esi]

mov eax, [eax+esi]
Equations in Assembly: SmplMath

NoCforMe

Whoa. Stop. Everyone shut up for one minute!

One thing at a time: you said this gave an assembler error:

bt [eax+esi],0

Of course it did. It's ambiguous: do you want to bit-test a word or a double word? (those are your choices with this instruction)

Try

bt DWORD PTR [eax+esi],0

(or whatever size you're trying to access here)
Assembly language programming should be fun. That's why I do it.

NoCforMe

#62
Quote from: dc on September 25, 2023, 08:24:34 AMi get pointer 'pArray' from globalAlocate
then try to access it like:
mov esi,index
shl esi,2
mov eax,pArray
bt [eax+esi],0
jc @f

OK, you're very close here. What you're trying to do makes sense.

Seems to me if you just remove the ambiguity of the bt instruction (use DWORD PTR), this should work as written.

One thing bothers me: the Microsoft documentation for GlobalAlloc() states that it returns a handle to the allocated memory*. Not sure if that's the same thing as a pointer which you can use directly. I use HeapAlloc() instead, which definitely returns a pointer. Why don't you try that instead? Any special reason to use GlobalAlloc()?

p.s.: As someone above pointed out, you can eliminate the shl esi, 2 by using

bt dword ptr [eax + (esi * 4)]

which does that arithmetic for you.

* Of course this could just be an ambiguity in the Micro$oft documentation ...
Assembly language programming should be fun. That's why I do it.

dc

i want to use this on allocated memory that can be any size depending...

NoCforMe

You can certainly do that as easily with HeapAlloc() as with GlobalAlloc(). You specify the size of allocation you want.
Assembly language programming should be fun. That's why I do it.

daydreamer

Check alloc macro,in qe macro help file
Returns a pointer to allocated memory or null if it fails allocate
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

NoCforMe

Macro, schmacro.
Just code it:

CALL GetProcessHeap ;Only need to do this once at program start:
MOV HeapHandle, EAX

INVOKE HeapAlloc, HeapHandle, 0, <how many bytes to allocate>
MOV <pointer to allocated memory>, EAX

Sheesh.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: dc on September 25, 2023, 06:10:48 AMim gonna have to assume that a pointer and an index are not used together at all in ml... please prove me wrong...
thanx

It's not our job to prove you wrong, it's your job to study the docs, play with code, and show in detail (i.e. with complete code) what's wrong, and what the error messages are.

Quote from: dc on September 25, 2023, 10:55:34 AMi want to use this on allocated memory that can be any size depending...

It really, really would help if you sat down, zipped your code and posted it here, instead of asking vague questions. Here is the demo that pointers and indexes can be combined. And guess what, it's complete code. Just copy & paste & build :biggrin:

include \masm32\include\masm32rt.inc

.data?
ThePointer    dd ?

.code
start:
  mov ThePointer, rv(GlobalAlloc, GPTR, 100)
  mov eax, ThePointer  ; not necessary because eax = ThePointer at this point
  bt word ptr [eax+4*esi], 3
  .if Carry?
    print "bit 3 is set", 13, 10
  .else
    print "bit 3 is clear", 13, 10
  .endif
  mov esi, 25
  mov eax, ThePointer
  mov byte ptr [eax+4*esi], -1
  bt word ptr [eax+4*esi], 3
  .if Carry?
    inkey "bit 3 is set"
  .else
    inkey "bit 3 is clear"
  .endif
  exit

end start

If you start asking what GPTR means, I'll contact your teacher :bgrin:

NoCforMe

Quote from: jj2007 on September 25, 2023, 06:08:06 PMIt really, really would help if you sat down, zipped your code and posted it here, instead of asking vague questions.

Well, in fairness, JJ, I don't think they should be required necessarily to post all of their code, which might be long, complicated and confused. I'd be happy just seeing the relevant parts, a condensed version.

I agree, asking vague questions ain't gonna get anybody nowhere.

OP, please post something from your code so we can get a better idea of what's going on.
Assembly language programming should be fun. That's why I do it.