Index | PAL Intro | Commands | Registers | Indices | Stack | Macros | Classes | Attributes | Errors


Manual Reference Pages  - reg_save (5)

NAME

reg/save() - Modify sections of text or byte strings

CONTENTS

Synopsis
Description
Error Handling
Examples
See Also
Author

SYNOPSIS

reg/save write, (#size)
reg/save write, (#value, #offset)
reg/save write, (#value, #offset, #mask)
reg/save write, ([text], #offset)

DESCRIPTION

Writes a 32-bit (4-byte) segment or text string to a given position within a STRING data type provided as a register. This instruction can also be used for modifying the length of a text or byte string sequence. A STRING data type is a register of type PSUNIT_TYPE_STRING.

In the first synopsis form, sets the length of the STRING data type in the write argument to the given size.

In the second and third synopsis forms, writes the lowermost 32 bits (4 bytes) in the given value at the position indicated by the offset argument within the STRING data type in the write argument. If the mask argument is provided, only the bits set in the lowermost 32 bits of the mask will be used from value and they will overwrite the corresponding bits in the original byte string. For example, if mask is #0xff000000, only the first byte will overwritten, the remaining bytes will be left untouched.

In the fourth synopsis form, writes the text to the given offset position within the STRING data type in the write argument.

The size, index, offset and mask arguments may be a register of type PSUNIT_TYPE_RAWIDX or a psInteger encoded in a PSUNIT_TYPE_XVALUE. The text argument may be a register of type PSUNIT_TYPE_PALTEXT or another PSUNIT_TYPE_STRING.

An offset of #0 represents the first byte position, #1 the second byte position, and so on. If the data to overwrite exceeds the length of the string in the write register, the extra bytes will be discarded. This instruction will not increase the length of a byte string, except when used in the first synopsis form. An out of range error occurs if offset is beyond the end of the text data.

ERROR HANDLING

A runtime error is generated if the requested offset is beyond the end of the text data or if an argument provided is of the wrong type.

EXAMPLES

The following copies the first 8 bytes from one string to another:

.main  
% Prepare strings
reg/copy P0, [  first test string]
reg/load P1, [ second test string]

% Prepare counter reg/load P2, #0
.loop   % Copy next 4 bytes from second string reg/load PUSH, (P1, P2)
% Save to first string reg/save P0, (PULL, P2)
% Increment the loop counter by 4 bytes op/add P2, P2, #4
% Continue loop if necessary reg/jmpne &[.loop], P2, #8
% Display contents of registers and exit obj/dump P0 reg/clr P0 func/rtn

The following example copies every other byte from one string to another:

.main  
% Prepare strings
reg/copy P0, [**********]
reg/load P1, [----------]

% Prepare counter reg/load P2, #0 reg/xload P3, (P0)
.loop   % Copy next 4 bytes from second string reg/load PUSH, (P1, P2)
% Save to first string with mask reg/save P0, (PULL, P2, #0xff00ff00)
% Increment the loop counter by 4 bytes op/add P2, P2, #4
% Continue loop if necessary reg/cmp P2, P3 reg/jmpeq &[.loop], SCMP, #2
% Display contents of registers and exit obj/dump P0 reg/clr P0 func/rtn

SEE ALSO

pal_commands(5), pal_registers(5), pal_indices(5), pal_macros(5), reg_load_text(5), reg_copy(5), reg_conv(5), op_mask(5),
PROSE Assembly Language at prose.sourceforge.net.

AUTHOR

Copyright (c) 2002-2018 Mark R. Bannister <cambridge@users.sourceforge.net>.

This is free software and can be downloaded from prose.sourceforge.net; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


PAL 1.0 reg_save (5) 16 January 2018
Generated by manServer 1.07 from man5/reg_save.5 using man macros.