Examining And Altering Memory With Basic - Omron SYSMAC CV500-BSC11 Operation Manual

Basic units
Table of Contents

Advertisement

Machine Language
Common Programming
Mistakes

6-3-3 Examining and Altering Memory with BASIC

Reading & Writing Memory
To check whether the program has been correctly saved or loaded, use the X
command immediately after the S or L command.
If an error has occurred, an error message (SAVE ERROR or LOAD ERROR) is
displayed.
Keep the following points in mind when developing a machine language subrou-
tine:
• Don't forget to allocate memory for the machine language program with the
MSET command.
• Remember that the storage address for the machine language program is the
sum of the segment address (DS0) and the offset (the specified address).
• Be careful not to erase or damage the system and BASIC program areas by
assembling or loading to the wrong section of memory.
• Before calling the machine language routine, use DEF SEG to define the ma-
chine language routine's segment address.
• To return from the machine language routine to the BASIC program, use the
RETF instruction. Make sure that the value of the stack pointer is the same as
when the machine language routine was called. Other registers and flags are
restored by the system.
• Do not disable interrupts in the machine language program.
• To use some of the memory allocated by the MSET command as a work area,
turn OFF the memory protect switch (write enable status).
• Instructions that are used for transferring data to or from the CPU Unit, or for
port operation such as PC READ and PC WRITE or PRINT and INPUT cannot
be programmed using the machine language.
To write data to the machine language program area from a BASIC program, use
the POKE statement. To read data, use PEEK.
Note The memory protect switch must be turned OFF for POKE to work.
Before reading or writing data in the machine language program area, define a
segment address with DEF SEG.
10 DEF SEG = &H400
To write data, use the POKE statement. (The memory protect switch must be
turned OFF.)
30 POKE &H100, &H41
To read the contents of memory, use the PEEK statement.
40 N = PEEK(&H100)
Here is a simple program that stores a value in memory, then reads it back and
displays it:
10 PARACT 0
20 DEF SEG = &H400
30 POKE &H100, &H41
40 N = PEEK(&H100)
50 PRINT CHR$(N)
60 END
70 END PARACT
In this program, addresses and data are specified as hexadecimal numbers.
However, they can also be specified in other formats or as variables.
Use segment &H400
. . . . . . . .
Store &H41 at location &H4100 (seg-
. . . . . . .
ment &H400 + offset &H100).
Read the contents of location &H4100
. . . . . . . .
and store in N.
Section 6-3
111

Advertisement

Table of Contents
loading

Table of Contents