Shop OBEX P1 Docs P2 Docs Learn Events
TAQOZ - bit masking - how to ? — Parallax Forums

TAQOZ - bit masking - how to ?

MaciekMaciek Posts: 674
edited 2021-08-06 18:47 in Forth

The problem:
I have a memory location I can't read from. It's write only. I need to change, say, 2 bits out of 8 but I also need not change the remaining 6 bits. Since I do not know their values and have no desire to overwrite them I need to mask them out while writing the byte.

The question:
Is there a way to mask out the bits to be left intact while writing the byte ?

Comments

  • Use a bit mask with SET and CLR but if you just want to write to certain bits then you could CLR all selected bits first then SET. However, if you are working with the value on the stack you can just use AND or ANDN to clear bits, then OR to set them. Is this to do with the RTC?

    Set and CLR.

    TAQOZ# long avar ---  ok
    TAQOZ# avar @ . --- 0  ok
    TAQOZ# 5 avar SET avar @ .l --- $0000_0005 ok
    TAQOZ# $A0 avar SET avar @ .l --- $0000_00A5 ok
    TAQOZ# 4 avar CLR avar @ .l --- $0000_00A1 ok
    
  • @"Peter Jakacki" said:
    Use a bit mask with SET and CLR but if you just want to write to certain bits then you could CLR all selected bits first then SET. However, if you are working with the value on the stack you can just use AND or ANDN to clear bits, then OR to set them. Is this to do with the RTC?

    Thanks, Peter.
    No, it is not related to the RTC :smile: It's for something else. The Control registers of the RV-3028 are always readable but if they were not, I would certainly like to be sure not to overwrite them unwillingly.

  • ErNaErNa Posts: 1,752
    edited 2021-02-24 16:23

    I try to imagine how TaQoz is able to read a register it will not tell me about ;-? I recall there are hidden registers in the P1. But if I ever wrote them, I could latch that information. And if they are read only, like input pins, it make no sense to not be able to read them.
    But those could be fake news registers were you are able to manipulate any information you never had.

  • Imagine this: you have an armed bomb and the time is ticking. To disarm the bomb you know you have to cut one blue and one red wire. There are also wires of other colours but you do not know what happens when you cut any of these. It might be nothing happens but it also might be the bomb explodes right into your face.
    Would you take the risk of chopping off all of the wires at one go or would you rather cut only the red and blue ones ?

    That basicaly was my problem, now solved thanks to Peter.
    As you can see, TAQOZ is so powerfull it can even disarm bombs :).

  • MaciekMaciek Posts: 674
    edited 2021-08-06 19:05

    This thread has been moved from the P2 category to ForthSpace and will continue here.

Sign In or Register to comment.