home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,567 of 4,675   
   Alexei A. Frounze to R.Wieser   
   Re: EXE program stack setup questions (1   
   08 Oct 18 21:26:27   
   
   From: alexfrunews@nospicedham.gmail.com   
      
   On Monday, October 8, 2018 at 5:58:33 AM UTC-7, R.Wieser wrote:   
   > Alexei,   
   >   
   > > I asked you specifically to use my code in the experiment.   
   >   
   > My apologies, I must have read over that, and assumed you wanted to see my   
   > results.   
   >   
   > -- My result using your code:   
   > 000 4D 5A 30 00 02 00 00 00 20 00 00 01 FF FF 00 00   
   > 010 30 10 00 00 00 00 00 00 22 00 00 00 01 00 FB 20   
   > 020 72 6A 00 00 00 00 00 00 00 00 00 00 00 00 00 00   
   > ...   
   > 200 8C C8 8E D8 8E C0 50 53 E8 08 00 83 C4 04 B8 00   
   > 210 4C CD 21 8D 7E F0 B9 10 00 32 C0 FC F3 AA 8B 46   
   > 220 04 03 46 06 C3 87 DB 87 DB 87 DB 87 DB 87 DB 90   
      
   The above disassembles as   
   ----8<----   
   00000000  8CC8              mov ax,cs   
   00000002  8ED8              mov ds,ax   
   00000004  8EC0              mov es,ax   
   00000006  50                push ax   
   00000007  53                push bx   
   00000008  E80800            call word 0x13   
   0000000B  83C404            add sp,byte +0x4   
   0000000E  B8004C            mov ax,0x4c00   
   00000011  CD21              int 0x21   
   00000013  8D7EF0            lea di,[bp-0x10]   
   00000016  B91000            mov cx,0x10   
   00000019  32C0              xor al,al   
   0000001B  FC                cld   
   0000001C  F3AA              rep stosb   
   0000001E  8B4604            mov ax,[bp+0x4]   
   00000021  034606            add ax,[bp+0x6]   
   00000024  C3                ret   
   ...   
   ----8<----   
      
   Whereas my executable disassembles as   
   ----8<----   
   00000000  8CC8              mov ax,cs   
   00000002  8ED8              mov ds,ax   
   00000004  8EC0              mov es,ax   
   00000006  50                push ax   
   00000007  53                push bx   
   00000008  E80800            call word 0x13   
   0000000B  83C404            add sp,byte +0x4   
   0000000E  B8004C            mov ax,0x4c00   
   00000011  CD21              int 0x21   
   00000013  55                push bp   
   00000014  8BEC              mov bp,sp   
   00000016  83EC10            sub sp,byte +0x10   
   00000019  53                push bx   
   0000001A  56                push si   
   0000001B  57                push di   
   0000001C  8D7EF0            lea di,[bp-0x10]   
   0000001F  B91000            mov cx,0x10   
   00000022  32C0              xor al,al   
   00000024  FC                cld   
   00000025  F3AA              rep stosb   
   00000027  8B4604            mov ax,[bp+0x4]   
   0000002A  034606            add ax,[bp+0x6]   
   0000002D  5F                pop di   
   0000002E  5E                pop si   
   0000002F  5B                pop bx   
   00000030  8BE5              mov sp,bp   
   00000032  5D                pop bp   
   00000033  C3                ret   
   ...   
   ----8<----   
      
   Somehow yours doesn't allocate space on the stack   
   for the local variables and expects BP to have a   
   meaningful value. Yours doesn't preserve BX, SI, DI   
   on the stack either.   
      
   Did you alter the code in my tiny0.asm?   
   Specifically, did you change this line   
     SomeFunction proc C   
   to   
     SomeFunction proc   
   ? Note the C in my code.   
   If you did, why?   
      
   Did you also ignore tasm's warning about the "uses"   
   line? Or did you remove the "uses" line yourself?   
      
   > And yes, I do see that SS stays zero here.   In other words: Tasm/Tlink can   
   > actually do what I want.   Thanks for bringing that under my attention. :-)   
      
   That was my point.   
      
   > A small problem though: I have absolutily no idea how to combine it with my   
   > regular setup (which handles a few things like arguments, used registers and   
   > local variables & labels rather conveniently) :   
   >   
   > - - - - - - - - - -   
   > .model TINY,STDCALL   
   > .386   
   > locals   
      
   All of these are OK.   
      
   > -- and eventually also   
   > .stack 0100h   
      
   You don't use this one. Instead you set up the stack   
   like I do, see the two lines near "myseg ends".   
      
   Here's my code adjusted:   
   ----8<----   
    file: tiny3.asm   
    assemble & link:   
      tasm tiny3.asm   
      tlink tiny3.obj   
   .model TINY,STDCALL   
   .386   
   locals   
      
   myseg segment para stack 'stack' use16   
       assume cs:myseg, ds:myseg, es:myseg, ss:myseg   
   start:   
       mov     ax, cs   
       mov     ds, ax   
       mov     es, ax   
      
       push    ax   
       push    bx   
       call    SomeFunction   
       add     sp, 4   
      
       mov     ax, 4c00h   
       int     21h   
      
   SomeFunction proc   
     arg @@wArg1:WORD,@@wArg2:WORD   
     uses bx,si,di   
     local @@bBuffer[16]:BYTE   
       lea     di, @@bBuffer   
       mov     cx, 16   
       xor     al, al   
       cld   
       rep     stosb   
       mov     ax, @@wArg1   
       add     ax, @@wArg2   
       ret   
   SomeFunction endp   
      
       align 16   
       db 4096 dup (?)   
   myseg ends   
      
   end start   
   ----8<----   
      
   Here's what it disassembles into:   
   ----8<----   
   00000000  8CC8              mov ax,cs   
   00000002  8ED8              mov ds,ax   
   00000004  8EC0              mov es,ax   
   00000006  50                push ax   
   00000007  53                push bx   
   00000008  E80800            call word 0x13   
   0000000B  83C404            add sp,byte +0x4   
   0000000E  B8004C            mov ax,0x4c00   
   00000011  CD21              int 0x21   
   00000013  C8100000          enter 0x10,0x0   
   00000017  53                push bx   
   00000018  56                push si   
   00000019  57                push di   
   0000001A  8D7EF0            lea di,[bp-0x10]   
   0000001D  B91000            mov cx,0x10   
   00000020  32C0              xor al,al   
   00000022  FC                cld   
   00000023  F3AA              rep stosb   
   00000025  8B4604            mov ax,[bp+0x4]   
   00000028  034606            add ax,[bp+0x6]   
   0000002B  5F                pop di   
   0000002C  5E                pop si   
   0000002D  5B                pop bx   
   0000002E  C9                leave   
   0000002F  C3                ret   
   ----8<----   
      
   Enter/leave and push/pop are all there as they   
   should be.   
      
   > - - - - - - - - - -   
   >   
   > > Hold on. How many segments does your code define?   
   >   
   > I use .CODE, .DATA (initialized data) and .DATA? (uninitialized data)   
   > declarations,   
      
   It's only now that you start telling us about the   
   structure of your code. Better later than never, eh? :)   
      
   I don't know yet if it's possible to keep those   
   directives. I'll take another look.   
   OTOH, if you can live without them, the above code   
   should work for you now.   
      
   > but because of the ".model TINY" declaration they all overlap.   
   > And than there is the ".stack {size}" declaration, which causes a seperate   
   > segment to be appended (no idea why though, as I've explicitily declared a   
   > TINY model).   
      
   Um, I'm not sure this combination (of model and stack   
   directive) is something that was ever intended to work   
   in an .EXE.   
   However, .stack isn't necessary as its main function   
   can be achieved by other means (see the code above).   
      
   ...   
   > But now you've proven that my Tasm / Tlink combination can actually do what   
   > I'm out for the only thing that needs to be figured out is how to get it   
   > from/combine it with my regular setup (which makes my programming life   
   > (much!) easier).   
   >   
   > ... which brings us back to my initial question.   
      
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca