TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: ANDREW FRANK
from: BRIAN MCCLOUD
date: 1997-04-17 05:05:00
subject: Accessing memory on heap

AF>First of all, I am very new to assembly programming, and don't have a book
AF>to learn from.  I'm using the Watcom compiler with inline assmbly to start
AF>(it's sure a lot easier than the 20+ lines needed in a bare bones assembly
AF>program which only returns to the OS).
AF>In all honesty, I probably won't ever go to writing programs entirely in
AF>assembly simply because C is so much easier.  I would however like to 
rite
AF>time sensitive portions of code in assembly.
AF>I have managed to write simple portions of code which takes 2 arguments,
AF>and returns one as the sum or the difference of the two, and simple stuff
AF>like that.
AF>What I'd like to do is pass a pointer variable to ASM, modify the data on
AF>the heap while in ASM, and return nothing having done my task.  (I know 
ow
AF>to return nothing).
AF>Another thing which I'm curious about is variables in Assembly.  I don't
AF>know how to define variables, so I've been passing variables and using
AF>them, or using the registers.  Also with regards to the registers, can you
AF>put floating point values in them, or just integers?
The FPU won't let you store data into the CPU registers or load data from the
CPU registers, but other than that, your ASM proc can't tell one data type
from another unless you tell it to.  Take the following two instructions for
example:
        FILD    DWORD PTR [BX]
        FLD     DWORD PTR [BX]
They both load from the same memory location, pointed to by BX, but the first
one loads it as an integer, and the second as an IEEE single-precision real.
If you're using a good assembler with a MODEL and declared your function as a
PROC in assembly, you can use something like this:
        LOCAL   varname:type
you can list several on one line, separated by commas.  "varname" is the name
of your variable, and "type" is a specifier telling it how much stack space 
o
allocate for it (BYTE, WORD, DWORD, QWORD, TBYTE, ...)
If you aren't using PROC statements, then here's the standard entry code for
most high level languages:
8086 code:
        PUSH    BP
        MOV     BP, SP
        SUB     SP, LocalSpace
80186+ code:
        ENTER   LocalSpace, 0   ; single instruction to do all of the above
Where LocalSpace is the total amount of space you need for your local
variables.  When I have my C compiler generated mixed code, it generates
comments showing what the stack offset for each variable is, and you'd access
them as [BP+disp] or [BP-disp], if they were parameters or local variables,
respectively.
Here's the standard exit code:
8086 code:
        MOV     SP, BP
        POP     BP
        RETF    Params
80186+ code:
        LEAVE   ; no operand needed, does the same as the first two above
        RETF    Params
((Cloud))
 * OLX 2.2 * Facts do not cease to exist because they are ignored.
--- PCBoard (R) v15.3/M 10
---------------
* Origin: Next time, Dial The Wrong Number! (209) 943-1880 (1:208/205)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.