NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: ben321 on December 16, 2023, 08:25:18 AM

Title: How do you overide the address size in NASM when using movsb?
Post by: ben321 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.
Title: Re: How do you overide the address size in NASM when using movsb?
Post by: debs3759 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
Title: Re: How do you overide the address size in NASM when using movsb?
Post by: ben321 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?
Title: Re: How do you overide the address size in NASM when using movsb?
Post by: debs3759 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.
Title: Re: How do you overide the address size in NASM when using movsb?
Post by: Frank Kotler on December 17, 2023, 10:34:21 PM

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

Best.
Frank

Title: Re: How do you overide the address size in NASM when using movsb?
Post by: debs3759 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.
Title: Re: How do you overide the address size in NASM when using movsb?
Post by: Frank Kotler 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