🔒 Locked
alloc in asm
Advertisement
Original Post
What operating system? What kind of assembly? System specific or platform independant? Usually you would just use the C standard library for this kind of stuff, unless you''re coding in 16 bit assembly, which means you would have to use the DOS api. And do be more specific next time.
In general, asm is for inner loops. malloc/free is not. The two should rarely encounter each other in any sane program.
I like pie.
I like pie.
The OS should provide an interface for making kernel function calls from userland code.
malloc and free will be one of these functions.
quote:You misunderstood him. malloc and free are commonly used together in C. Malloc and free are not commonly used at all in asm, because the parts of your code that you write in asm should not be the parts where you do allocation.
Original post by Yohomyth
if the two are rarely used together, why is it so common is c++ programs?
"Sneftel is correct, if rather vulgar." --Flarelocke
There are of course ways to allocate and free memory directly in ASM, normally via BIOS/INT calls (long time since I coded pure ASM). If thats what you want I'll try and dig out the details.
However, having said that, if you are coding for Windows, you might as well use the functions of the environment, as described above.
Yours,
Archimage
(Ann-Marie Ratcliffe)
[edited by - Archimage on May 11, 2004 7:31:06 PM]
However, having said that, if you are coding for Windows, you might as well use the functions of the environment, as described above.
Yours,
Archimage
(Ann-Marie Ratcliffe)
[edited by - Archimage on May 11, 2004 7:31:06 PM]
quote:
Original post by Sneftel
You misunderstood him. malloc and free are commonly used together in C. Malloc and free are not commonly used at all in asm, because the parts of your code that you write in asm should not be the parts where you do allocation.
How do you know he isn''t doing just ASM?
quote:
Original post by Puzzler183
How do you know he isn''t doing just ASM?
I kind of assumed he''d have a basic degree of common sense. Chris Sawyer might decide he''s going to code an entire game in ASM, but the rest of us are somewhat more prudent.
"Sneftel is correct, if rather vulgar." --Flarelocke
quote:
Original post by Sneftel
I kind of assumed he'd have a basic degree of common sense. Chris Sawyer might decide he's going to code an entire game in ASM, but the rest of us are somewhat more prudent.
Much as I'd love to defend pure ASM (I wrote my first game in pure 6502 Assembler (Acorn BBC B) and since written complete apps in x86 ASM for DOS and Win3.1), from Win95 onwards, I have to admit you might as well use what you can get from the SDK even if the rest of the code is ASM.
Yours,
Archimage
(Ann-Marie Ratcliffe)
(I can always remember when I finally got the split screen working on the BBC B (change mode 2/3's down the screen from VSync) so I could have high res and 16 colours on the same screen..... only to buy Elite and see that they had done it first
[edited by - Archimage on May 12, 2004 6:36:28 AM]
quote:
Original post by Archimage
There are of course ways to allocate and free memory directly in ASM, normally via BIOS/INT calls (long time since I coded pure ASM). If thats what you want I''ll try and dig out the details.
However, having said that, if you are coding for Windows, you might as well use the functions of the environment, as described above.
Yours,
Archimage
(Ann-Marie Ratcliffe)
[edited by - Archimage on May 11, 2004 7:31:06 PM]
Memory management is part of the OS. A normal PC BIOS doesn''t care about that stuff (why should it at all).
quote:
Original post by quasar3d
And afaik, those interupts don't work in windows, or at least you don't have the privelage to use them. The dos api were those interupts, in windows it are c style functions, and so you have to use them.
Whilst it is possible to do it purely in ASM, you are right in that it gets very messy working around Windows - you basically have to duplicate what Windows does in its allocation/free functions, including pacifying Windows as regards privileges etc - so you might as well use the ones provided.
quote:
Original post by VolkerG
Memory management is part of the OS. A normal PC BIOS doesn't care about that stuff (why should it at all).
Ok, scrub the BIOS mention (it was a long day). Having said that, its actually the processor that knows about memory allocation etc - unless you are saying that you need an OS on which to write a new OS which does memory management - And that OS whould obviously need a OS that it was written on/in so it could do memory management - And that OS would need....
Archimage
[edited by - Archimage on May 12, 2004 6:33:14 AM]
alternatively you can use that thing called COM *shudders*
(if you didnt know, i cheated and stole this info from the MASM32 libraries ;-) )
Edit: Damn tags
[edited by - ZedFx on May 12, 2004 10:43:37 AM]
.data
Alloc_pIMalloc DWORD 0
.code
; modifies eax, ecx, edx
Alloc proc public cb:DWORD
.IF !Alloc_pIMalloc
invoke CoGetMalloc,1 , ADDR Alloc_pIMalloc
.IF eax
xor eax, eax ; NULL return pointer
ret
.ENDIF
.ENDIF
push cb
mov ecx, Alloc_pIMalloc
mov ecx, [ecx]
call DWORD PTR [ecx] + 12
ret
Alloc endp
; modifies eax, ecx, edx
Free proc public pv:DWORD
push pv
push Alloc_pIMalloc
mov ecx, Alloc_pIMalloc
mov ecx, [ecx]
call DWORD PTR [ecx] + 20
xor eax, eax
ret
Free endp
(if you didnt know, i cheated and stole this info from the MASM32 libraries ;-) )
Edit: Damn tags
[edited by - ZedFx on May 12, 2004 10:43:37 AM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement