Skip to content

Conversation

@dancrossnyc
Copy link
Collaborator

Add a reader token that will swap the top two
elements on the stack, which means we can do things
like this:

wrsmn # . setbits 1,4 0b101 . rdsmn @0x1230_0000

Which will,

  1. Push 0x12300000 onto the stack
  2. Duplicate it so that the stack has two copies
    of 0x12300000
  3. Call rdsmn which will pop the first copy and read whatever
    is at that SMN address (this is just an example; assume it is
    a valid SMN address) and push it onto the stack. The stack
    now contains the value it read via SMN, as well as the
    0x1230_000 pushed earlier
  4. Push 0b101, 1,4 and invoke setbits, which will pop the first
    three values (1,4, 0b101 and the contents of the SMN register
    read a moment ago). Set bits will set bits 1..=3 in the SMN
    value to 101 and push that onto the stack. The stack now
    contains the modified SMN value and 0x12300000.
  5. Swap the top two elements of the stack, so that it now
    contains the SMN address at the top, then the modified value
  6. Invoke wrsmn which will pop the address and value, and
    write the value to that SMN address.

And we're done. This may be clearer using the | syntax:

rdsmn @0x1230_0000 | setbits 1,4 0b101 | wrsmn #

Signed-off-by: Dan Cross [email protected]

Add a reader token that will swap the top two
elements on the stack, which means we can do things
like this:

    wrsmn # . setbits 1,4 0b101 . rdsmn @0x1230_0000

Which will,

1. Push 0x12300000 onto the stack
2. Duplicate it so that the stack has two copies
   of 0x12300000
3. Call `rdsmn` which will pop the first copy and read whatever
   is at that SMN address (this is just an example; assume it is
   a valid SMN address) and push it onto the stack.  The stack
   now contains the value it read via SMN, as well as the
   `0x1230_000` pushed earlier
4. Push 0b101, 1,4 and invoke setbits, which will pop the first
   three values (1,4, 0b101 and the contents of the SMN register
   read a moment ago).  Set bits will set bits 1..=3 in the SMN
   value to `101` and push that onto the stack.  The stack now
   contains the modified SMN value and 0x12300000.
5. Swap the top two elements of the stack, so that it now
   contains the SMN address at the top, then the modified value
6. Invoke `wrsmn` which will pop the address and value, and
   write the value to that SMN address.

And we're done.  This may be clearer using the `|` syntax:

    rdsmn @0x1230_0000 | setbits 1,4 0b101 | wrsmn #

Signed-off-by: Dan Cross <[email protected]>
Copy link

@citrus-it citrus-it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be FORTH before you know it.

@dancrossnyc dancrossnyc merged commit ed9fcd1 into main Apr 10, 2025
5 checks passed
@dancrossnyc
Copy link
Collaborator Author

Lol. :-D

@dancrossnyc dancrossnyc deleted the swap branch April 10, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants