www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/24/10:00:33

From: Larry Swanson <laswanson AT mwci DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: NASM + DJGPP newbie problem
Date: Wed, 17 Sep 1997 07:52:49 -0500
Organization: MidWest Communications, Inc.
Lines: 136
Message-ID: <341FD2A0.54CC1C76@mwci.net>
NNTP-Posting-Host: dial-54.man.mwci.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hello

I recently decided to learn how to program in assembly using NASM and
DJGPP.  I'm having a problem trying to get the following code to work.
(I usually get a message like 'access denied') that appears to be when I
push something on the stack.

Also I have a few questions
I know that  SS=stack selector,  CS = code selector, DS= data selector
and that ES is extra selector. My question is, what are fs and gs? can I
put a selector for the LFB there and leave it there or does DJGPP use it
for anything?
Also I am learning ASM just using "Michael Abrash's Zen of Code
optimization" and "Interfacing DJGPP with assembly procedures."  Could
any body reccomend some better learning materials.(These are both
excellent documents but they are exactly trying to teach asm.) 

Thank you again;



Here is my code(lifted from	"Interfacing DJGPP with assembly
procedures.")

[BITS 32]

[GLOBAL _AddFour]
[GLOBAL _VersionString]
[GLOBAL _Return_Test]
[GLOBAL _Print]

[EXTERN _printf]
[EXTERN _Exported]
[EXTERN _variable]


[SECTION .text]
;---------------------------------------------------------------------------->
;prototype AddFour(unsigned int x);
;
;---------------------------------------------------------------------------->

x_add_four equ 8

_AddFour:
         push  ebp;
         mov ebp , esp;

         mov eax , [ebp + x_add_four];
         add eax , [AddConstant];
         ;leave reult in eax for return to c

         mov ebp,esp
         pop ebp
         ret
;End of
AddFour-------------------------------------------------------------->


;-----------------------------------------------------------------------------
;prototype unisgned int Return_Test(void);
; this returns the global variable "variable"
;-----------------------------------------------------------------------------
_Return_Test:
             push ebp
             mov ebp,esp

             mov eax,[_variable]


             mov ebp,esp
             pop ebp
             ret
;end
return_test--------------------------------------------------------------

;-----------------------------------------------------------------------------
;prototype Print();
;-----------------------------------------------------------------------------

_Print:
         push ebp
         mov ebp,esp

         push  dword _VersionString
         push  dword PrintTemplate1
         call _printf

         push dword [_Exported]
         push dword PrintTemplate2
         call _printf



         mov ebp,esp
         pop ebp
         ret
;end
Print--------------------------------------------------------------------


[SECTION .data]

AddConstant       dd 00000004h   ; d-word

_VersionString    db "NASMTEST.ASM-Version 0.0a",00h  ;array of bytes

PrintTemplate1    db "VersionString = '%s'",0ah,00h
PrintTemplate2    db "unsigned int Exported = 0x%8x",0ah,00h




//now my c file

#include <stdio.h>
#include <stdlib.h>
extern unsigned int AddFour(int x);//assembly language procedure
extern char VersionString[];
extern unsigned int Return_Test(void);
extern void Print();

int Exported=0xfff00ffa;
int variable =0xdeadbeef;

int main(){

    int test=4;

    printf("\ntest =%i",test);
    printf("\nAddFour(test)=%i",AddFour(test));

    printf("\n Return_Test()=0x%X\n",Return_Test() );
    Print();
    return 0;
}

- Raw text -


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