Shop OBEX P1 Docs P2 Docs Learn Events
DIRA,OUTA,INA,shl in PASM — Parallax Forums

DIRA,OUTA,INA,shl in PASM

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2010-01-23 18:22 in Propeller 1
I have some questions about the I/O control in ASM. For example, in the following:

or dira, #%10


what is setting the pin and what is setting the status? Does the OR set the status and the binary set the pin? If so what command (OR, AND, XOR, NOR, etc.) sets dira to in and which to out? If you wanted to turn on pin 10 would you do it:
and outa, #%11

Do·you use the same sign as you did for the dira to choose the -/+ of the outa?!?
That and is there an ina in PASM? If so, how·do you use it?

Thanks,
Micro

P.S. I am also curious: what is the purpose of shr and shl? Shifting bits doesn't seem to be all·that useful......

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Computers are microcontrolled.

Robots are microcontrolled.
I am microcontrolled.

SX Spinning light display·

http://designedbymemicros.blogspot.com/

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2010-01-23 14:02
    microcontrolled: You should read about the DIRA & OUTA·instructions in the Prop Manual that comes with PropTool.

    The or dira,#%10 is merely making P1 an output without altering any other pin. See the OR instruction.

    The and outa,#%11 makes all output pins zero except P0 & P1. See the AND instruction.

    Shifting bits is extremely useful. It is used to compile bit patterns, extract bit patterns and other useful things. Take a look at FullDuplexSerial to see how the character input and output routines use shl & shr.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-23 14:08
    DIRA and OUTA are just 32-bit memory locations (much like with the Stamps) with each bit corresponding to a specific I/O pin. By default, these locations are zeroed when the cog is started. The I/O mode is initially input (0) and you set it to output (1) by setting the bit to one by whatever means you want. The output state is initially zero and you set it to one by setting that bit. The exact instruction doesn't matter. ANDN and OR are the most convenient, particularly for I/O pins 0-8.

    If, by status, you mean input mode state, that's set only by the state of the I/O pin itself. The INA bits correspond to the I/O pin states. You can't really set them except by changing the I/O pin state. They (the INA bits) even reflect the output state if the I/O mode (DIRA bit) is set to output.

    To set a bit of any memory location (say OUTA) to one (say bit 3 of 31-0 for example), you do

    OR OUTA,ioMask

    To clear a bit, you'd do

    ANDN OUTA,ioMask

    To check if a bit is true (copy it to the zero flag), you'd do

    TEST ioMask,INA wz

    where

    ioMask LONG %1000

    Note that you need ioMask as a separate location because of how the TEST and INA work. INA is a source location only and must come in the source field of the instruction which is where the immediate value normally goes. If you put INA in the destination field, you're really manipulating a "shadow" memory location rather than the I/O hardware and the instruction won't do what you expect it to.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-01-23 18:22
    Shifting bits is VERY useful. Each bit you shift left is like multiplying by powers of 2; say you need to take a value and multiply it by eight -- it becomes

    shl     value, #3
    



    Shifting right divides by powers of two; to get the high byte of a 16-bit value you could do this:

    mov     lsbval, value
    shr     lsbval, #8
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.