Hello Again
I have only a little question about this cpp Array
static char str[20][100] = {' ',};
Ist this correct in Masm i try to understand a cpp source
str db 20, 100 dup(0)
Regards,
i am not sure, but it looks like a 20 x 100 array
Hello Dave
I also think, and what is {' ',}; first char is a space?
Hello ragdog,
That code will produce one space character followed by 1999 NULL characters.
Disassembling the code:
.386
option dotname
.model flat
public _main
_data SEGMENT DWORD PUBLIC 'DATA'
@8 label byte
db 20H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
db 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
.
.
.
db 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
_data ENDS
static char str[20][100] = {' ',};
i believe that creates an array of 20 strings, 100 characters each, and fills them with spaces
i am not a C guy, so i may be wrong
each of the 20 strings might be zero-terminated, too - i don't know
Thank you both
Quote
_data SEGMENT DWORD PUBLIC 'DATA'
@8 label byte
db 20H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
db 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
.
.
.
db 00H, 00H, 00H, 00H, 00H, 00H, 00H, 00H
_data ENDS
Thats right Vortex i understand the same but gives a syntax for it in Masm
expl:
str 2000 dup (?) <{" "}> ; i know thats not works ;)
Ok a solution is :
str db 20h
db 1999 dup (?)
But i have think it gives a similar solution like cpp
i would probably do this
.DATA?
str db 2000 dup(?)
.CODE
start:
mov edi,offset str
mov ecx,sizeof str/4
mov eax,20202020h
rep stosd
Right Dave this is a simply and knowing solution but i have think it is posible in Masm to define in the data section like cpp
of course you can
.DATA
str db 2000 dup(20h)
that makes the EXE almost 2 KB larger though
Right
I use now a Allocated memory and add the first char a space
Thanks you,
Try this algo.
http://masm32.com/board/index.php?topic=4050.0
str db 20*100 dup(" ")
Quote from: mabdelouahab on February 22, 2015, 05:41:52 PM
str db 20*100 dup(" ")
You probably didn't read Dave's posting (http://masm32.com/board/index.php?topic=4046.msg42635#msg42635). Your executable will be bigger because of that data block.
Hello ragdog,
The closest MASM comes to that cpp syntax is this:
str db 20 dup (100 dup (' ',))
This fills all 2000 bytes with 20h. I *think* cpp does the same, the other 1999 are not zero's; but I hate cpp so have a memory block here. The rows are not 0-delimited.
Have a look at this chapter from "The Art of Assembly", Section 5.6.1 Arrays (http://courses.engr.illinois.edu/ece390/books/artofasm/CH05/CH05-2.html#HEADING2-16).
Yes, this will increase your .exe by 2K, but that's what cpp does; static arrays are always initialized, with 0's if nothing else.
Well, since you have to deal with it, I hope u like cpp better than I do. Used to love C but after C++ even that's distasteful. Good luck!
Thank you all for this infos
QuoteYes, this will increase your .exe by 2K
What is 2 k todays gives programs with many Mbs :lol:
But my goal was to understand this cpp source