NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: munair on April 09, 2020, 03:28:36 PM

Title: How to define a fixed length string padded with zeros
Post by: munair on April 09, 2020, 03:28:36 PM
While working on the SharpBASIC compiler I wonder how to define a null-terminated fixed length string.

Consider the following SharpBASIC code:

Code: [Select]
var buffer: string * 10 = $32;
This should be parsed into a NASM string with 10 spaces plus a null. The SharpBASIC compiler currently generates the following NASM code:

Code: [Select]
buffer times 10 db 32
          times 11-$+buffer db 0

Is this the correct output or is there a better syntax?
Title: Re: How to define a fixed length string padded with zeros
Post by: debs3759 on April 09, 2020, 04:18:14 PM
I would use

Code: [Select]
buffer times 11 db 0

That will give you the 10 length string plus the zero terminator.
Title: Re: How to define a fixed length string padded with zeros
Post by: munair on April 09, 2020, 04:48:06 PM
I would use

Code: [Select]
buffer times 11 db 0

That will give you the 10 length string plus the zero terminator.

That was my initial solution as well. But the string may be predefined with characters like in the example above the space character (32), or something else like
Code: [Select]
var buffer: string * 10 = "abcde";