# MX\_USRLOD

> [HTML Version](mx_usrlod.htm)

**xcall MIAMEX, MX\_USRLOD, idx, fspec\$ \{,flags, var, count\}**

MX\_USRLOD (MIAMEX 108) allows you to create and load a memory module from a file or a variable. Unlike under AMOS, this can be done while running a BASIC program. 

**Parameters**

_idx_  ([Num](num.md))  \[out\]

will return the index entry number where the module was loaded, or 0 if not loaded. (-1 indicates that the module was already locked into memory.)

_fspec\$_  \[in\]

must be set to the specification of the file to load into memory. (If the USRMEM\_NOFILE flag is specified, then _fspec_ just sets the name of the module in memory.)

_flags_  ([Num](num.md))  \[in\]

may be set to any sensible combination of the memory module flags. Normally this would only be used to set the USRMEM\_LOCKED flag to lock the module in memory, or to specify the USRMEM\_NOFILE flag (which is required when loading the module from a variable). See [MX\_USRMAP](mx_usrmap.md) for a table of applicable flags.

_var_  [(BLOB](blob.md))  \[in\]

When specified in conjunction with the USRMEM\_NOFILE flag, the module is loaded directly from the specified variable. This provides a mechanism similar to COMMON[xs](keyword-types.md), which has the advantage of not having any particular limits on the module size or name.

_count_  \[in\]

This parameter makes it easier to load full or partial arrays into a memory module.

When _flags_ contains USRMEM\_NOFILE (meaning that the module is to be loaded from contents of the variable _var_, with _fspec\$_ indicating the desired name of the memory module), then if _var _is actually an array element, e.g. VAR(1), then _count _can be specified to indicate the number of elements to load starting with the specified element. For example:

MAP1 ARRAY(70),S,25

XCALL MIAMEX,MX\_USRLOD,MIDX,"MYMOD.SYS",USRMEM\_NOFILE,ARRAY(1),70



The above would load 70 elements of the array, starting with ARRAY(1) into a memory module named "MYMOD.SYS", whose index number would be returned in MIDX.

**Warning #1**: It is impossible for the subroutine to know whether the _count _value you specify is actually valid (i.e. not larger than the array), so the responsibility is yours.

**Warning #2**: The type of the array must not be F6 or F4. These two types get converted to F8 by the general subroutine handler, causing the address of the array seen by the subroutine to not match that seen by the caller.

**Note:** _count_ is the number of array elements, not the number of bytes.  In the example above, count is specified as 70, which results in 70 elements of the array, or 70 x 25 = 1750 bytes being loaded.  In contrast, to read/write more than one array element at a time in MX\_USRIO, you would need to specify the number of bytes, not elements. This is a likely error when using both MX\_USRLOD and MX\_USRIO together.

See the notes under [MX\_USRMAP](mx_usrmap.md) for more information on A-Shell’s user memory architecture.

**See Also**

•	[LOAD.LIT](load_lit.md) which is the typical way to load a module into memory.