flat assembler
Message board for the users of flat assembler.

Index > Main > Pointers - allocate and free memory

Author
Thread Post new topic Reply to topic
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
I am creating MOPS which translates MOPSCode to asm and then compiles it with fasm.

I want to have functions like ObjectPascals "GetMem" or Cs "malloc" and, of course, "FreeMem" and so on.

But I have no Idea how to do that. It should go with all OSs, or a special Version for every one. The Pointer should be written into bx (32-Bit ebx) before the "call" command.

Thanks if someone can post Ideas or Code.

PS: Sorry for my English. I can read English texts very well, but not write. OK, I am 15 years old and I can learn much in the next 4 Years until I leave school.

_________________
http://www.falter.de.tf and http://www.forum.falter.de.tf

(C) Felix Alter


Last edited by FAlter on 18 Jun 2004, 12:27; edited 1 time in total
Post 08 Jun 2004, 19:26
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
Has anybody understood what I mean? If yes, is there anyone who can help me?
Post 11 Jun 2004, 17:40
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
maybe you could describe what you want without using that terms like "MOPS" which are not very well known...
Post 11 Jun 2004, 18:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
What do you mean "it should go with all os's"?
Post 11 Jun 2004, 18:49
View user's profile Send private message Reply with quote
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
vid wrote:

maybe you could describe what you want without using that terms like "MOPS" which are not very well known...


I need procedures like GetMem/FreeMem (Delphi) or in C malloc and mfree (?), but in Assembler.

madmatt wrote:

What do you mean "it should go with all os's"?


Well, there should be a method for Windows, one for DOS, and maybe one for Linux. But it is better if the procedure for Windows is the same like the one for Linux and DOS (32-Bit, I know that 16-Bit-DOS needs an own procedure).

me wrote:

The Pointer should be written into bx (32-Bit ebx) before the "call" command.


I meant the Pointer to the Pointer, so the procedure can update it.
Post 13 Jun 2004, 10:28
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
There is no thing such as a "universal memory allocation thing". Under dos it's one thing, under windows another, and linux a third... or, well, you could link with libc, then it's going to be a call to malloc on all platforms. On most 32bit OSes, the same calling convention is used - eax,ecx,edx trashable, ebx,esi,edi,ebp must be preserved, and function return values are put in EAX, not EBX.

Btw, I would suggest that you drop dos support, 16bit anyway... you can write dos apps as win32 console instead, and use a dos extender with limited win32 emulation, like Michael Tippach's WDOSX.
Post 13 Jun 2004, 12:11
View user's profile Send private message Visit poster's website Reply with quote
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
There is NO Returnvalue. MOPS puts Returnvalues in AH/AX/EAX (depending on 8/16/32 Bit). A Procedure or Function should save bx before using it. But the programmer can tell the compiler that the Parameter is in bx, and in this way it may be faster in some cases.
Post 13 Jun 2004, 14:32
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
What *IS* that MOPS thing you keep talking about?

If it's some system you're writing yourself, you might want to go with the standard FASTCALL convention rather than inventing your own, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core___fastcall.asp
Post 13 Jun 2004, 15:29
View user's profile Send private message Visit poster's website Reply with quote
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
Actually, I'm creating MOPS. You can test the MOPS alphaversion, but I think you won't because it's only in german...

And I want to allocate memory, but how? I have got some Ideas with self-created tables, but I think it's very slow and so I'm looking for the traditional way doing it.
Post 13 Jun 2004, 17:34
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Okay, so it's a programming language/environment/something of your own? Better stick to standard calling conventions, including FASTCALL Smile

The traditional way to allocate memory is to either use libc (since it's available on almost every platform, and every platform that matters anyway) - the other would be to use whatever the OS gives you (HeapAlloc or VirtualAlloc on win32, sbrk/syscalls on *u*x) - or, if you're writing an OS or embedded code, you could manage the memory yourself. Or, in some very peculiar situations, you could have a large static array (ie, "whole bunch of zeroes") in your executable file, and only use that memory...
Post 13 Jun 2004, 18:31
View user's profile Send private message Visit poster's website Reply with quote
Custodian



Joined: 08 Jun 2004
Posts: 10
Location: Russia
Custodian
I have trouble with such code...
Code:
handle dw ?
...
mov bx,[handle]
mov ax, word [bx]        ; <--- This works perfectly
mov dx, word [bx+2]
...                 ; <--- I don't change anything at bx & handle
mov word [bx], dx     ;\<--- here, VDM of Windows 2000 make an error
mov word [bx+2], ax   ;/        
...
    

Smile This is exchanging of 2 words... but it dosn't work... Crying or Very sad
I post hex bytes of error in VDM later.... today at 16.00-18.00.

thx...
Post 15 Jun 2004, 07:50
View user's profile Send private message MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
What do you do inbetween those lines, though? Any INT calls perhaps?
Post 15 Jun 2004, 11:32
View user's profile Send private message Visit poster's website Reply with quote
Custodian



Joined: 08 Jun 2004
Posts: 10
Location: Russia
Custodian
No... no any int calls, not any modification of bx register...

here is a full code of nearest operations
This is a COM program, using 16-bit dos
Code:
start:
...
     mov cx,254
     @1:
     push cx

     mov cx,254
     @@:
     xor ax,ax
     mov al,cl
     shl ax,1
     mov bx,c_table
     add bx,ax
     mov ax,word [bx];levoe
     mov dx,word [bx+2];pravoe

     cmp ax,dx
     jae next
;start of part 1 ----
     mov word [bx+2],ax
     mov word [bx],dx
;end of part 1 ----
     mov bx,c_table
     add bx,cx
     xor ax,ax
     mov al,byte [bx]
     mov ah,byte [bx+1]
     mov byte [bx+1],al
     mov byte [bx],ah
next:
     loop @r
pop cx
loop @1

;start of part 2 ----
mov byte [path],'~'
mov dx,path     
mov ax,5b00h  
mov cx,0  
int 21h
jc error     
;end of part 2 ----
    


There is an error, if both part a in my code... if I comment one of them, code works...

c_table & p_table is two arrays of 256 & 512 bytes
Errors in VDM of Windows 2000 (SP4)
OP:63 06 94 00 00
or
OP:fe fd 00 00 fe
Undefined instruction
Crying or Very sad
thx...
Post 15 Jun 2004, 13:31
View user's profile Send private message MSN Messenger ICQ Number Reply with quote
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
Quote:

No... no any int calls, not any modification of bx register...


Code:
;start of part 1 ---- 
     mov word [bx+2],ax 
     mov word [bx],dx 
;end of part 1 ---- 
     mov bx,c_table  ;REALLY???
     add bx,cx  ;NO modification???
    


But why are you posting here if you have an other problem than me and you can't help me?
Post 15 Jun 2004, 14:14
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Custodian



Joined: 08 Jun 2004
Posts: 10
Location: Russia
Custodian
FAlter wrote:

Code:
;end of part 1 ---- 
     mov bx,c_table  ;REALLY???
     add bx,cx  ;NO modification???
    


But why are you posting here if you have an other problem than me and you can't help me?


You don't quite understand... There is no modification at befour part 1. And it doesn't work fine with addressation using BX register Sad

_________________
--- Line of Cut ---
Post 15 Jun 2004, 17:20
View user's profile Send private message MSN Messenger ICQ Number Reply with quote
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
Sorry. I thought you ment modifications of bx between a"part 1" and "part 2", but if I compare it with your code above, you're right.

But you have ignodes another Question:
me wrote:

But why are you posting here if you have an other problem than me and you can't help me?
Post 16 Jun 2004, 18:56
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Custodian



Joined: 08 Jun 2004
Posts: 10
Location: Russia
Custodian
I thought that the theme of this theard is pointers, so I post here my program with error (as I think) in poniters...
Post 17 Jun 2004, 08:38
View user's profile Send private message MSN Messenger ICQ Number Reply with quote
FAlter



Joined: 08 Jun 2004
Posts: 19
Location: Mixdorf, Germany
FAlter
But if you had read the text above, you had seen that the topic is simething more special than only pointers (the title). My problem is how to allocate or free memory. And of course, you should use pointers for this action.

I changed the title now. I think that's better.
Post 18 Jun 2004, 12:31
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.