NASM + DJGPP linking 
Author Message
 NASM + DJGPP linking

Umm, I have written the following for NASM:

[SECTION .text]

GLOBAL _setmode     ; setmode(int mode)

_setmode:
    push bp
    mov bp, sp

    push ax
    push dx

    mov ax, [bp+4]
    int 10h

    pop dx
    pop ax

    pop bp

    ret

and compiled it as a COFF, then I compiled it with this file :

extern void setmode(int mode);

void main(void) {
    setmode(0x13);

Quote:
}

using the line (DJGPP):

Quote:
>>gcc main.c graphics.o

creating a file a.exe

when I run a.exe, nothing happens.  But it should change to screen 13h.
What is happening, can somebody please help!

David



Sat, 15 Dec 2001 03:00:00 GMT  
 NASM + DJGPP linking
SP points to topmost stack value. You do:
        push BP
        mov BP, SP
which sets [BP]=(old BP), [BP+4]=(return address), [BP+8]=first
argument.

Therefore you need to  use [BP+8] instead of [BP+4].

Davin.

On Tue, 29 Jun 1999 14:05:57 +1200, "David Mitchell"

Quote:

>Umm, I have written the following for NASM:

>[SECTION .text]

>GLOBAL _setmode     ; setmode(int mode)

>_setmode:
>    push bp
>    mov bp, sp

>    push ax
>    push dx

>    mov ax, [bp+4]
>    int 10h

>    pop dx
>    pop ax

>    pop bp

>    ret

[snip]

Quote:

>when I run a.exe, nothing happens.  But it should change to screen 13h.
>What is happening, can somebody please help!

>David

__________________________________________________________

my programming page: http://yoyo.cc.monash.edu.au/~davmac/


Sat, 15 Dec 2001 03:00:00 GMT  
 NASM + DJGPP linking

Quote:

> _setmode:
>     push bp
>     mov bp, sp

>     push ax
>     push dx

>     mov ax, [bp+4]
>     int 10h

>     pop dx
>     pop ax

>     pop bp

>     ret

    Aside from changing bp+4 to bp+8, you also don't have to preserve ax or
dx (in DJGPP).

--
     -Rolf Campbell (39)3-6318



Sat, 15 Dec 2001 03:00:00 GMT  
 NASM + DJGPP linking

Quote:

> Umm, I have written the following for NASM:
>     mov bp, sp
. . .
>     mov ax, [bp+4]
>     int 10h
. . .
> and compiled it as a COFF, then I compiled it with this file :
. . .
> using the line (DJGPP):
> >>gcc main.c graphics.o

  DJGPP is a 32-bit environment.  That means you must use
esp instead of sp, ebp instead of bp, and ebp+8 instead of
bp+4.

  DJGPP is a protected mode environment.  Instructions like
"int 10h" cannot go directly to the BIOS.  They must be
intercepted by the DOS extender and redispatched in V86 or
real mode.

  DJGPP code can be run several different environments (such
as CWSDPMI or Windows DOS boxes etc.).  I don't remember whether
all, some or none of them redispatch int 10h's for you.  I
expect it is in the FAQ.
--
http://www.erols.com/johnfine/
http://www.geocities.com/SiliconValley/Peaks/8600/



Sat, 15 Dec 2001 03:00:00 GMT  
 NASM + DJGPP linking
thank you all for your help, I am most grateful that I don't have to code in
AT&T syntax (hehe)

David.



Sun, 16 Dec 2001 03:00:00 GMT  
 NASM + DJGPP linking
On Tue, 29 Jun 1999 14:01:12 -0400, "John S. Fine"

Quote:

>  DJGPP is a 32-bit environment.  That means you must use
>esp instead of sp, ebp instead of bp, and ebp+8 instead of
>bp+4.

For some reason I missed that. Must be too used to 16-bit assembly
code.

Quote:
>  DJGPP is a protected mode environment.  Instructions like
>"int 10h" cannot go directly to the BIOS.  They must be
>intercepted by the DOS extender and redispatched in V86 or
>real mode.

I think you are incorrect - any interrupts under DPMI are echoed
through to V86/real mode with the same register values; it is only the
functions which use pointers which have to be caught by a DOS
extender.

Of course, issuing interrupts this way is probably not the recommended
way of calling BIOS services, it would be better to use the DPMI
functions.

Quote:
>  DJGPP code can be run several different environments (such
>as CWSDPMI or Windows DOS boxes etc.).  I don't remember whether
>all, some or none of them redispatch int 10h's for you.  I
>expect it is in the FAQ.

As far as I understand it, they all should as it's part of the DPMI
specification.

Davin.

__________________________________________________________

my programming page: http://yoyo.cc.monash.edu.au/~davmac/



Sun, 16 Dec 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Help interfacing NASM and DJGPP...

2. ALink with DJGPP and NAsm?

3. Need help : Problem building a vesa lib with nasm&djgpp

4. Problem building a vesa lib with nasm&djgpp

5. GCC/DJGPP/NASM - HELP!

6. Help interfacing NASM and DJGPP...

7. ALink with DJGPP and NAsm?

8. nasm+gcc+djgpp

9. NASM i386 object, with DJGPP

10. Free NASM / DJGPP box drawing code

11. Using NASM to making files for DJGPP (newbie)

12. Need help : Problem building a vesa lib with nasm&djgpp

 

 
Powered by phpBB® Forum Software