From: alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams) Newsgroups: comp.os.msdos.djgpp Subject: Re: DJGPP stack when calling a function? Please help. Date: Sun, 13 Apr 1997 19:13:03 GMT Message-ID: <3350d7b0.6866403@news.demon.co.uk> References: <19970413111500 DOT HAA07345 AT ladder01 DOT news DOT aol DOT com> NNTP-Posting-Host: abwillms.demon.co.uk Lines: 109 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On 13 Apr 1997 11:15:10 GMT, nitehawk91 AT aol DOT com wrote: >Greetings ! Hello! >parameters; >return address; 4 bytes >stack pointer ; 4 bytes >I have a function that looks like this : func(short, short, short) >Now the stack would look like : >short 3; 2 byte >short 2; 2 byte >short 1; 2 byte >return adress ; 4 byte >stack pointer ; 4 bytes This is providing you have stored EBP. >Now I tied to access the three parameters as following : > >mov eax, [esp+8] ; short 1 to eax >mov ebx, [esp+10] ; short 2 to ebx >mov ecx, [esp+12] ; short 3 to ecx Ah, right. Those are short ints, but you're reading long ints from them, as 32 bit registers. Try: _my_func: push ebp mov ebp,esp mov ax,[ebp+8] mov bx,[ebp+10] mov cx,[ebp+12] pop ebp ret Note that I keep ebp as my frame pointer. This means that I can PUSH and POP temporary values to my heart's content, and still keep track of my stack frame amongst all that. Also note that I am using the 16 bit registers ax, bx, and cx to store the 16 bit values found in short ints. >This compiles and the programm works fine, but I get idiotic results. >(BTW : The assembler function doesn't return a value) If it did, stick it in eax. Eg: ; extern "C" int add(int a,int b) _add: push ebp mov ebp,esp mov eax,[ebp+8] add eax,[ebp+10] pop ebp ret For little functions, feel free to stop storing ebp and all that, instead using offsets on esp but minus 4 since we're not storing ebp there any more. >2. Pointer access problem : >assume I have char string[] = {'h','e','l','l','o'}; >In C I could access the 'e' for example with string[1] or *(string+1). >How can I make this in Nasm ? >I have declared [EXTERN _string] >Tried to access the 'e' with mov eax,[_string+1] >This doesn't work also. Why ? Similarly, you're using eax (32 bits) to access a char (8 bits). Try: mov al,[_string+1] Also make sure that _string really is the array - not a char* pointing to it, as declared by: char *string = "hello"; >Please help me. "But now those days are gone, I'm not so self assured..." >Thank's NEtime :-) >Matthias > ABW -- "Plug and Play support: WfEWAD will autodetect any installed Nuclear Arsenals, Laser Satellites, Battlefield Control Networks, Radar Installations, Fighter Squadrons, and other WfEWAD compliant devices, including the new Macrosoft Unnatural Keyboard, with full support for the now-famous Big Red Buttom(tm)." (Windows for Early Warning and Defence User's manual P26) Alaric B. Williams Internet : alaric AT abwillms DOT demon DOT co DOT uk Hello :-)