Executable memory

Alan alanpotteiger at gmail.com
Fri Oct 4 14:13:21 PDT 2013


On Friday, 4 October 2013 at 21:10:30 UTC, Adam D. Ruppe wrote:
> On Friday, 4 October 2013 at 20:50:09 UTC, Alan wrote:
>> Does anyone have an example of how to maybe print a character 
>> to the string with a  system call?
>
> yeah on Linux the assembly is:
>
>   string a = "hello!";
>   auto sptr = a.ptr;
>   auto slen = a.length;
>   version(D_InlineAsm_X86)
>   asm { // 32 bit
>        mov ECX, sptr;
>        mov EDX, slen;
>        mov EBX, fd;
>        mov EAX, 4; // sys_write
>        int 0x80;
>    }
>    else version(D_InlineAsm_X86_64)
>    asm { // 64 bit
>       mov RSI, sptr;
>       mov RDX, slen;
>       mov RDI, fd;
>       mov RAX, 1; // sys_write
>       syscall;
>    }
>
> I gotta run, so I'll leave translating that into machine code 
> an exercise for the reader (you could compile it in D then 
> objdump it), at least until I get back to the computer :)

Alright, thanks for the help Adam!


More information about the Digitalmars-d-learn mailing list