Author Topic: How do you overide the address size in NASM when using movsb?  (Read 2201 times)

Offline ben321

  • Full Member
  • **
  • Posts: 182
How do you overide the address size in NASM when using movsb?
« on: December 16, 2023, 08:25:18 AM »
For example, in 16 bit mode, the movsb command looks only at the si and di registers (first 16 bits of the esi and edi registers). However I can use "db 0x67" to manually insert the address size override byte in front of the movsb opcode. This will force it to use the entire 32bits of the esi and edi registers. However, I'm wondering if there's a proper instruction for this. I've tried "movsb long", and "movsb far". And so far I can't find any instruction that will cause NASM to write the 0x67 byte in front of the opcode for movsb.

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 221
  • Country: gb
    • GPUZoo
Re: How do you overide the address size in NASM when using movsb?
« Reply #1 on: December 16, 2023, 05:38:46 PM »
You can use the a32 prefix to override the address size. In your case, that would be

Code: [Select]
a32 movsb

Similarly, to use 16 bit addressing in 32 bit code, you can use the a16 prefix

To override operand size, it's o16 and o32
My graphics card database: www.gpuzoo.com

Offline ben321

  • Full Member
  • **
  • Posts: 182
Re: How do you overide the address size in NASM when using movsb?
« Reply #2 on: December 17, 2023, 01:50:36 AM »
You can use the a32 prefix to override the address size. In your case, that would be

Code: [Select]
a32 movsb

Similarly, to use 16 bit addressing in 32 bit code, you can use the a16 prefix

To override operand size, it's o16 and o32

Thanks for the info. Is that somewhere in the manual? Or more of a hidden function?

Also, movsb is usually used with rep, so where does the a32 go in this case? Before or after the rep?
« Last Edit: December 17, 2023, 01:53:34 AM by ben321 »

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 221
  • Country: gb
    • GPUZoo
Re: How do you overide the address size in NASM when using movsb?
« Reply #3 on: December 17, 2023, 05:09:35 PM »
Yes, it's in the manual, that's what I checked before replying. In version 2.07 of the manual, it's described in section 10.3. In version 0.98, it was section 9.3. They're the two version I currently use for reference.

I think the REP would be the first prefix, so you repeat the o32 each time round. Not sure on that though, it may work the other way round as well.
My graphics card database: www.gpuzoo.com

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How do you overide the address size in NASM when using movsb?
« Reply #4 on: December 17, 2023, 10:34:21 PM »

"rep" gets its parameter from cx or ecx. np?

Best.
Frank


Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 221
  • Country: gb
    • GPUZoo
Re: How do you overide the address size in NASM when using movsb?
« Reply #5 on: December 17, 2023, 11:51:37 PM »

"rep" gets its parameter from cx or ecx. np?

Best.
Frank

Yes. I guess o16/o32 would override which is used, and come before the rep. Haven't tried it though, so not sure on that.
My graphics card database: www.gpuzoo.com

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How do you overide the address size in NASM when using movsb?
« Reply #6 on: December 18, 2023, 12:10:17 AM »
Hi  Debs.
I think I may have misunderstood the question. Seems like a good one to "try it and see what works"/

Best,
Frank