CompuServe Thread

#Args for AllocMem

4 messages in this thread
#118469From: Thomas HoladayAug 31, 1990 5:12 PM
I want to mannage memory dynamically (the way I would with malloc & free), making calls to the exec library functions AllocMem() and FreeMem(). I need units large enough to hold a File Information Block. I can see in CAPE:includes/libraries/dos.i a LABEL statement named fib_SIZEOF, which certainly _looks_ as if it somehow could be construed as the size I want, but I don't know how to use it. AllocMem() wants a quantity-of-bytes in d0. Is it this simple? INCLUDE 'dos.i' … move.l fib_SIZEOF,d0 … or do I need #fib_SIZEOF, or fib_SIZEOF(pc)? I can't find "LABEL" in the manual anywhere; I bet it's a macro, huh? THol() { cout << "Sir, I exist." ;}
#118471From: Bill HawesAug 31, 1990 5:49 PM
Thomas, To load a structure size you want to do a move.l #fib_SIZEOF,d0 to put the immediate value in register D0. Note that the instruction move.l fib_SIZEOF,d0 is valid but subtly incorrect: it uses absolute addressing to load the *contents* of the address given by the fib_SIZEOF symbol. This catches me every so often, as it's easy to miss the # when you type in a program. The LABEL directive is a macro that sets the supplied symbol to the size of the structure at that point. Since structure sizes are usually multiples of 2 or 4, you can sometimes save a little code by loading half or a quarter of the size using moveq (2 bytes) followed by an add or shift (2 bytes), instead of the longword move (6 bytes.) For example, moveq #fib_SIZEOF>>2,d0 lsl.w #2,d0 -Bill
#118546From: Martin MurraySep 1, 1990 9:40 AM
I couldn't (and in fact, didn't) say it better myself.
#118649From: Thomas HoladaySep 1, 1990 11:18 PM
Thanks for your lucid explanation on the difference between fib_SIZEOF and #fig_SIZEOF in a move.l expression. Have you considered writing an "Assembler for ARexx Programmers" text? I admit it isn't a large market, but you'd have 100% of it. THol() { cout << "Sir, I exist." ;}