assembler copy char[]

Thomas Kuehne thomas-dloop at kuehne.cn
Thu Jun 7 07:06:30 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

nobody schrieb am 2007-06-07:
> Frits van Bommel Wrote:
>
>> nobody wrote:
>> > i try copy mystring to st in assembler. 
>> > Can someone give me an advice how to do this.
>> > 
>> > import std.stdio;
>> > void main()
>> > {
>> >         char[] mystring = "Hey Assembler\n";
>> >         char[] st;
>> > 
>> >         asm
>> >         {
>> >                 mov EAX, dword ptr [mystring+4];
>> >                 mov st,EAX;
>> >         }
>> >         writefln("st: ", st);
>> > }
>> > 
>> > I get a Segmentation fault .
>> 
>> Unsurprising, since you're copying mystring.ptr to st.length, creating 
>> an array reference to a (likely huge) array with (.ptr == null) ;).
>> 
>> Like Daniel, who posted while I was composing this post, I wonder why 
>> you're trying to do this. There's a much easier way that can likely be 
>> better optimized by the compiler.
>> But if you're determined to do this (or are just trying to expand your 
>> knowledge of asm coding and/or D array implementation), read on.
>
> Yes i try to learn Inline Assembler but it is more
> difficult then i thought ;-)

If you like to learn inline assembler the hard way have a look at the
asm_*d files at http://dstress.kuehne.cn/run/a . Some of those require
the helper http://dstress.kuehne.cn/addon/cpuinfo.d . Please don't read
cpuinfo.d because it uses various hacks to get around some GDC bugs.

Thomas


-----BEGIN PGP SIGNATURE-----

iQIVAwUBRmgcs7ZlboUnBhRKAQIWOQ//e/NKJudP318iTZbFArlXub3Ppl0b/fwk
qPbu5TfnQ1FX0z+sY1jWxiuTmtt/k3qg/RcPViqI8XWt58xElXH2DB9/eM+fD56i
ChLpHfExMkq276GTx1MeWfGTDYB07rJQJ6gnvRF0QNWg8Iiaw+tRYBzuyCSxl8nJ
IwV/21vVA80iDjCPMzboC+2oR30Esx0HKWwB8n1wNQR4u6RlPw0zclV3/O+R7uZv
PYZP6qMFNV63Y019zRPi2VpdpTfLJuIp9/qlyGijErus1VfeXIqBmzFztAxx4948
EnpGC/L3fVX13kdvdYI15nXEBXzmypP2yLrTcRUb248GkknQLSxORVl2JwLo4Ljc
BUxFMGpHept8wDTthYPkyOQx5k5nRERduyq3xsq2ki+7Lj5gBt79mUuzC95xF2FB
nH2vpJ9QZDnaTlnhH+RmOR/Q7WlvgS5e2N2rjZw3bR9YspgjtJFHwox5XtMdPau8
mL1+lHHtuqo+/R+XxOBm51CbW/PKXisuAEbMRkT4lWOAcW3UAxWS0OoNVzsE0hFi
vCom5sX9AgPgeTPf2cM5nVAe0s24D4QkNvLV5NNsSk+KPFNzb02Gyxz5QxkFU9kF
mAFSQIkHGTOvi93lJ8LGyjDpK4ORLETBS9hTgagFoR5UHGBhCiNhusunzrZxlrIi
VygfeM0kBCs=
=WwyP
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list