Author Topic: Use a pointer in a register?  (Read 13713 times)

nobody

  • Guest
Use a pointer in a register?
« on: March 29, 2005, 12:04:02 AM »
I'm trying to do a project for my assemble class, using NASM. When I try to run a program with this line: "or BYTE PTR [eax], [upperMask]", it gives me the error "comma or end of line expected".

Basically, eax contains a pointer to a character in a string, and I want to convert it to uppercase by OR'ing it with 0x40.

But, my professor's lecture notes are horrible, and I can't find anything on the web about what I'm trying to do.

How can I make it do what I want?

Thanks,
Josh

nobody

  • Guest
Re: Use a pointer in a register?
« Reply #1 on: March 29, 2005, 12:29:17 AM »
Never mind, I got an answer on comp.lang.asm.x86. Apparently, you can't use OR on two memory addresses.

This worked:
        mov BL, [upperMask]
        or  [EAX], BL

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Use a pointer in a register?
« Reply #2 on: March 29, 2005, 04:28:58 AM »
Hi Josh,

Okay - you can get answers a lot of places. Actually "or byte ptr [eax], [upperMask]" had a couple of problems... Besides "[mem], [mem]" instructions not existing - it applies to more than just "or" (we have only one data bus) - Nasm doesn't use the "ptr" keyword... just "or byte [eax], ...". The "..." can't be memory - could be a register like bl (in which case you wouldn't need to tell Nasm "byte" - the register tells Nasm  the size), or could be an "immediate" - a plain number (in which case Nasm *can't* determine the size, you have to tell it).

If "upperMask" is a variable...

upperMask db 0x40

Then your solution will work (assemble, at least). If you defined "upperMask" as a "constant"...

upperMask equ 0x40

then you could do "or byte [eax], upperMask"... (this is what "Arargh" was talking about)

Now... perhaps my memory fails me, but 0x40 is *not* the value I recall for "upperMask". I remember 0x20... If your routine is giving "weird" results, try that.

Best,
Frank