Shop OBEX P1 Docs P2 Docs Learn Events
ASM shift register brain lock — Parallax Forums

ASM shift register brain lock

bte2bte2 Posts: 154
edited 2012-02-08 18:39 in Propeller 1
Hi all, I have a string of 3 CD4014 PISOs which are reading 24 different switches for a fault monitoring system.

I have it running perfectly in Spin, but I have been trying to learn ASM lately, and I am stuck on a kinda basic problem.

I don't want anybody to provide finished code or anything, and I searched and could only find Spin examples. I also looked through the Object Exchange.

I have synchronous serial data arriving on Port P19 (pin 22 QFP). I want to put this pin state into the LSB of a long variable, shift it left, clock the 4014s, and repeat this 23 more times, and end up with a long with the upper 8 bits clear, and the lower 24 bits reflecting the states of the 24 inputs on the 4014s.

I have everything figured out except the part about actually putting P19 into bit 0 of my variable. My clock and latch outputs appear to be working fine, so I know I am not too far off.

I clear the variable before calling the shift loop, so if the serial data is 0 I can just shift the already existing 0 into the LSB.

This would imply a simple 'if-then' ie; IF (PIN=1) THEN VAR.BIT0 = 1, but I am having trouble thinking through exactly what I need to do in Propeller Assembly.

The project runs fine in Spin, this is only for my own edification. Thanks in advance.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-07 14:23
    Load ina into a scratch variable, shift it right by 19, and and it with 1. Then you can or the scratch variable into your result.

    The more PASMish way is to do a test on ina, using a mask in the dst field, setting the z flag. Then, use that condition to or a 1 into your result or not.

    -Phil
  • bte2bte2 Posts: 154
    edited 2012-02-07 14:28
    Thank you Phil!
  • bte2bte2 Posts: 154
    edited 2012-02-08 06:55
    Hi Phil, your first suggestion works, but your second suggestion leads to what is perhaps the source of my initial confusion.

    If you could help me get past this last mental block, I sure would be much appreciative.

    I am having a little trouble figuring out how to TEST ina, using a 9-bit literal. This seems to be a recurring stumbling block for me, merging the 32-bit memory and IO aspects of the Propeller with the 9-bit operand limitations of PASM.

    It is entirely possible that I am just overthinking this and my brain is getting in the way.

    I promise that I am reading the manuals, and not looking for any easy way out.

    Thanks big, -bry

    ETA- I think that it has to do with assigning the bit mask to a memory location (that can be referenced with 9 bits), and using that as the mask, but like I said, I am having a serious brain lock for some reason.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-02-08 07:21
    Actually, a TEST INA,<anything> won't work for other reasons. INA is a read-only register and, because of the way the special registers are implemented, if you use one of these in the destination (first) field of an instruction, you will get a "shadow" memory location rather than the register value. You need to do a TEST <mask>,INA like this:
    CON
    ioPinNumber =   17   ' I/O pin 17 for example
    DAT
    ' .....
                TEST   maskValue, INA   wc   ' or wz
       if_c     JMP   #whereToGo   ' or any other instruction
    ' .....
    maskValue   LONG   1 << ioPinNumber   ' or any other I/O pin mask
    
    You could also shift in the bits easily using:
    TEST   maskValue, INA   wc
                ADDX   finalValue, finalValue
    
    This adds a long to itself shifting left one bit, then adds in the carry flag effectly shifting in the input bit.
  • bte2bte2 Posts: 154
    edited 2012-02-08 07:46
    Thank you (again) Mike, extremely helpful!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-02-08 08:16
    bte2,

    'Sorry for being so terse. When I said to put the mask in the dst field, I should have explained why. Thankfully Mike was there, not only to cover for me, but to provide an even shorter solution! :)

    -Phil
  • Mark_TMark_T Posts: 1,981
    edited 2012-02-08 08:45
    I would prefer RCL to ADDX here, purely on stylistic grounds (the instruction's name matches your intention better)
               TEST   maskValue, INA   wc
               RCL    finalValue, #1
    
  • bte2bte2 Posts: 154
    edited 2012-02-08 18:39
    bte2,

    'Sorry for being so terse. When I said to put the mask in the dst field, I should have explained why. Thankfully Mike was there, not only to cover for me, but to provide an even shorter solution! :)

    -Phil

    None taken- thank you for responding, I really do appreciate it!
Sign In or Register to comment.