Forum

Register Variables?
 
Notifications
Clear all

Register Variables?

5 Posts
2 Users
1 Reactions
88 Views
Posts: 21
Topic starter
(@aadhoc4370)
Eminent Member
Joined: 5 months ago

Firstly, this is great. I love anything that makes code more declarative & readable.

I wonder about using "register variables"

The example `DIM MYVAR 0xFF` look like you're doing replaces, such as `REGLOD 0x1 MYVAR 0x0` becomes `REGLOD 0x1 0xFF 0x0`
The example `DIM MYREG #R5` might be a "replace" as well, so `IF 0x1 MYREG 0x08` would be `IF 0x1 #R5 0x08` ?!?!?
But, what happens with a `GETADDR 0x1 MYREG 0x0`? Does it become `GETADDR 0x1 #R5 0x0` ? I think the docs say the syntax must be `GETADDR 0x1 0x5 0x0`

This doc text is my confusion:
In code, if you are getting a value from the register then you need to use #Rn where n is the register number. If you are doing anything to a register other then using its value then you should simply use the register number for the argument.

I've found I have to specifically use `#R10` or `0xa` depending on situation and had to create my own converter (via preprocessing).
Have you changed something, or is there special handling or more uniform handling now for registers, or "register variables"?

Or have I misunderstood something?
Thanks


4 Replies
Posts: 90
Admin
(@nivbot)
Member
Joined: 9 months ago

It will automatically use it as needed. So if you declare a register variable like DIM VAR1 #R0. it you can use VAR1 anywhere to replace a register whether it be just the register number or the #Rn tag


Reply
1 Reply
(@aadhoc4370)
Joined: 5 months ago

Eminent Member
Posts: 21

@nivbot
Nice that the variable can be both #R10 and 0xa depending on context.
Going back and forth with my preprocessing got kinda ugly.

Oh hey, what does this do?
```
1 DIM MYREG #R5
2 REGLOD MYREG 0x1 0x0
3 GETADDR 0x1 MYREG 0x0
4 DELMS MYREG 0x0 0x0
5 DELMS #R5 0x0 0x0
```

Points:
1) I think REGLOD stores 0x1 into register 5
2) Does GETADDR store into register 5? or store into register 1 (the "value in" register 5)?
3) I think lines 4 and 5 are equivalent. They both refer to 0x1 (the value in #R5)

I'm getting your intent, so I think I know how points (1) and (3) would behave.
I'm wondering about point (3).
Maybe I'm missing the rock-solid description you've established for this feature.
I can see myself doing something ambiguous.... like `GETADDR 0x1 MYREG 0x0` when I mean store in register 5... but I might try that same line to store in register 1 (the value in the referenced register 5)


Reply
Posts: 90
Admin
(@nivbot)
Member
Joined: 9 months ago

That REGLOD would store 1 in register 5 and yes 4 and 5 are equivalent. 


Reply
1 Reply
(@aadhoc4370)
Joined: 5 months ago

Eminent Member
Posts: 21

A "rock-solid" explanation is needed for the documentation.

```
DIM MYREG #R5
REGLOD MYREG 0x1 0x0   /* same as: REGLOD 0x5 0x1 0x0 */
REGLOD 0x5 0x1 0x0        /* 0x5, the register number */
REGLOD #R5 0x1 0x0       /* Incorrect syntax */

IF MYREG #R2 0xF            /* same as: IF #R5 #R2 0xF */
IF 0x1 MYREG 0xF             /* same as: IF 0x1 #R5 0xF */
SET8 MYREG #R1 0x1       /* same as: SET8 0x5 #R1 0x1 */
GETADDR 0x1 MYREG 0x0 /* same as: GETADDR 0x1 0x5 0x0 */
```

There are clearly 2 different scenarios above (reg number & reg value).
Let's be extremely clear on this. You have documented this but I think we can do better: "In code, if you are getting a value from the register then you need to use #Rn where n is the register number. If you are doing anything to a register other then using its value then you should simply use the register number for the argument."

How about a suggestion like this for the register documentation?

1) Register number (ex: 0x5): ONLY for opcodes that return a value.
    When a register is needed to store a result.
    Example GETADDR: Read the Current Address Bits Into a Register, such as `GETADDR 0x1 0x5 0x0` which reads 0x1 bits into register 5.
    Example REGLOD: Load a value into a Register, such as `REGLOD 0x5 0xff 0x0` which stores 0xff into register 5.
2) Register value (ex: #R5): ANYWHERE ELSE.
    When you want to pass the value in a register as an opcode argument.
    Example SHOSTR: Display Output, such as `REGLOD 0x3 0x1 0x0; SHOSTR #R3 0x0 0x0` which shows string 0x1 (from register 3) at 0,0.
    Example IF: Conditional, such as `IF 0x0 #R7 0x0` which means "IF value in register 7 equals 0".
3) Register variables: The opcode's argument type is honored.
    When you use a register variable for a Register number argument, the register number will be passed.
    When you use a register variable for a Register value argument, the value in the register will be passed.
    Example `DIM MYREG #R3; REGLOD MYREG 0x1 0x0; SHOSTR MYREG 0x0 0x0` stores 0x1 into register 3, then shows string 0x1 at 0,0.
    NOTE: In `GETADDR 0x1 MYREG 0x0` the value in the MYREG register is NOT received by GETADDR since that argument is contextually a Register number argument (meaning the opcode needs to store a value, not receive a value).

P.S. You might want to consider having the semicolon be recognized by tokenizer as a newline marker. Will make examples easier to show (like above), and maybe even a few places having grouped commands on one line, such as `SHOSTR; UDSCRN; DELMS` which are often together. (Might be troublesome for your text area box's syntax highlighting though)


Reply
Share: