www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/13/20:24:38

Date: Fri, 13 Mar 1998 17:23:26 -0800 (PST)
Message-Id: <199803140123.RAA06087@adit.ap.net>
Mime-Version: 1.0
To: sochaxx AT flash DOT net (art socha), djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: more NASM/DJGPP HELP please...

At 08:58  3/12/1998 -0800, art socha wrote:
>okay. so i got video mode 320x200,256 going with nasm/djgpp. next 
>problem... should be simple but... i'm probably just blind...
>
>calling a procedure from djgpp like so...
>
>for(y=0;y<199;y++)
> for(x=0;x<319;x++)
>  plot(x,y,15);
>
>neat. here is the assembly procedure.

Somebody answered your question already. I'll add a couple of things:

* Your assembly routine needs to save ebx. It might be better if you used
some other register. (esi and edi must also be saved.)

* You will get better performance if you can avoid the 16-bit operations.
They require a byte prefix and at least one additional cycle.

* GCC has a neat trick it uses to optimize this kind of thing:

eax = x, edx = y

lea edx, [edx+edx*4] ; edx * 5
shl edx, 6           ; edx * 320
add edx, eax

Voila! Much smaller and faster. Why use a CISC processor if you're not going
to *use* it? :)

* Since you're writing to a buffer, you can do this:

memset(vid, 15, 320 * 200);

Be amazed at the speed increase. This is of course not completely general.

>
>global _plot ;called from c    plot(int x; inty; char col);
>_plot:
>        push    ebp
>        mov     ebp,esp             ;point to stack
>        xor     eax,eax             ;eax=0
>        xor     ebx,ebx             ;ebx=0
>        mov     word eax,[ebp+10]   ;eax = y
>        mov     word ebx,[ebp+8]    ;ebx = x
>        xchg    ah,al               ;y * 256
>        add     bx,ax               ;bx = (y*256)+x
>        shr     ax,2                ;ax = (y*64)
>        add     bx,ax               ;bx = (y*320)+x
>        add     dword ebx,[_vid]    ;add our offset to the video pointer
>        mov     byte al,[ebp+12]    ;al = color
>        mov     byte [ebx],al       ;draw it!
>        pop     ebp
>        ret
>
>the _vid address is defined and calculated in the c program. this is the 
>flat address of the video segment and works perfectly.
>
>the problem is that apparently i'm not getting my x,y, nor color from the 
>stack. according to logic, since we are using 32-bit addressing now, 
>[ebp+8] should point to the first parameter. I confirmed this in the 
>NASM.DOC file as well. Anyway, I'm stumped for now... I need to find a 
>good Protected Mode Debugger so I can see what's going on (if you know of 
>one lemme know where to get it eh?)

DJGPP has `edebug32', `fsdb', `gdb', and RHIDE.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019