Skip to Main Content Skip to Search
Product Documentation

regwrite - Write data values to registers on processor

Syntax

IDE_Obj.regwrite('regname',value,'represent',timeout)
IDE_Obj.regwrite('regname',value,'represent')
IDE_Obj.regwrite('regname',value,)

IDEs

This function supports the following IDEs:

Description

IDE_Obj.regwrite('regname',value,'represent',timeout) writes the data in value to the regname register of the target processor. regwrite converts value from its representation in the MATLAB workspace to the representation specified by represent. The represent input argument defines the format of the data when it is stored in regname. Input argument represent takes one of three input strings.

represent StringDescription

'2scomp'

Write value to the destination register as a signed integer value in two's complement format. This is the default setting when you omit the represent argument.

'binary'

Write value to the destination register as an unsigned binary integer.

'ieee'

Write value to the destination registers as a floating point 32-bit or 64-bit value in IEEE floating-point format. Use this only when you are writing to 32- and 64-bit registers on the target.

String regname specifies the name of the destination register on the target. IDE handle, IDE_Obj defines the target to write value to. Valid entries for regname depend on your target processor. Register names are not case-sensitive — a0 is the same as A0.

For example, MPC5500 processors provide the following register names that are valid entries for regname.

Register NamesRegister Contents
'acc'Accumulator A register
sprg0SPR registers

For example, C6xxx processors provide the following register names that are valid entries for regname.

Register NamesRegister Contents

A0, A1, A2,..., A15

General purpose A registers

B0, B1, B2,..., B15

General purpose B registers

PC, ISTP, IFR, IRP, NRP, AMR, CSR

Other general purpose 32-bit registers

A1:A0, A2:A1,..., B15:B14

64-bit general purpose register pairs

Other processors provide other register sets. Refer to the documentation for your target processor to determine the registers for the processor.

To limit the time that regwrite spends transferring data to the target processor, the optional argument timeout tells the data transfer process to stop after timeout seconds. timeout is defined as the number of seconds allowed to complete the write operation. You might find this useful for limiting prolonged data transfer operations.

If you omit the timeout input argument in the syntax, regwrite defaults to the global time-out defined in IDE_Obj. If the write operation exceeds the time specified, regwrite returns with a time-out error. Generally, time-out errors do not stop the register write process. The write process stops while waiting for the IDE to respond that the write operation is complete.

IDE_Obj.regwrite('regname',value,'represent') omits the timeout input argument and does not change the time-out value specified in IDE_Obj.

IDE_Obj.regwrite('regname',value,) omits the represent input argument. Writing the data does not reformat the data written to regname.

Reading and Writing Register Values

Register variables can be difficult to read and write because the registers which hold their value are not dedicated to storing just the variable values.

Registers are used as temporary storage locations at any time during execution. When this temporary storage process occurs, the value of the variable is temporarily stored somewhere on the stack and returned later. Therefore, getting the values of register variables during program execution may return unexpected answers.

Values that you write to register variables and local variables during intermediate times in program operation may not get reflected in the register.

To see if the result is consistent, write a line of code that uses the variable. For example:

register int a = 100;
int b;
 ...
b = a + 2;

Reading the register assigned to a may return an incorrect value for a but if b returns the expected 102 result, nothing is wrong with the code or the software.

Examples

To write a new value to the PC register on a C5xxx family processor, enter

IDE_Obj.regwrite('pc',hex2dec('100'),'binary')

specifying that you are writing the value 256 (the decimal value of 0x100) to register pc as binary data.

To write a 64-bit value to a register pair, such as B1:B0, the following syntax specifies the value as a string, representation, and target registers.

IDE_Obj.regwrite('b1:b0',hex2dec('1010'),'ieee')

Registers B1:B0 now contain the value 4112 in double-precision format.

See Also

read | regread | write

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS