Shop OBEX P1 Docs P2 Docs Learn Events
indexing through variables in asm question — Parallax Forums

indexing through variables in asm question

Rick_HRick_H Posts: 116
edited 2010-10-13 07:48 in Propeller 1
I have a bunch of things I am doing for each output on my I2C bus per channel.

This is a small example
I2Coutput
                      cmp  setting1,    #1   wz
   if_z              mov   sin,           out1
   if_z              call   #HalfSin
   if_z              mov   out1,        sin

                      cmp  setting2,    #1   wz
   if_z              mov   sin,           out2
   if_z              call   #HalfSin
   if_z              mov   out2,        sin

                      jmp #I2Coutput


sin long 0
setting1 long 0
setting2 long 0

out1  long 0
out2  long 0

how would I use djnz and an index to get the variables in order?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-12 08:50
    For just two different sets of variables, you're probably worse off trying to use an index. For more than two, it starts to make sense
    movd theCmp, #setting1  ' initialize addresses
                                    movs theMov1, #out1
                                    movd theMov2, #out1
                                    mov   count, #3   ' loop count
    
    theCmp                      cmp  setting1,    #1   wz
    theMov1  if_z              mov   sin,           out1
                 if_z              call   #HalfSin
    theMov2  if_z              mov   out1,        sin
                                    add   theCmp,    dest1   ' increment destination
                                    add   theMov1,   #1
                                    add   theMov2,   dest1
                                    djnz  count,       #theCmp
    
    dest1                         long  1 << 9
    
  • Rick_HRick_H Posts: 116
    edited 2010-10-12 08:54
    ya I have 8 channels on my DAC, I was just trying to give a simple example of what I want. This makes sense to me thanks Mike.

    I am currently at 328 longs on just this asm code so I want to make some subs to save memory.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-10-12 08:58
    I use this subroutine to read values from a PASM table
    ' basepntr = address of array/table
    ' idx = index of element to read
    ' value = value that is read
    
    read                    mov     tmp1, basepntr
                            add     tmp1, idx
                            movs    rdval, tmp1
                            nop
    rdval                   mov     value, 0-0
    read_ret                ret
    

    You could do something like this:
    sendvalues              mov     basepntr, #out1                 ' start of values
                            mov     idx, #0                         ' start with first
    :loop                   call    read                            ' get a value
                            ' do something with value
                            add     idx, #1                         ' update index
                            cmp     idx, #8                 wz, wc  ' done?
            if_b            jmp     #:loop
    
  • Rick_HRick_H Posts: 116
    edited 2010-10-12 09:46
    The more I look at asm the dumber I feel. I am so used to thinking about Code as just a syntax but asm is just binary registers. Hopefully I can wrap my brain around it some more without destroying my illusion of how processors work lmao.
  • Rick_HRick_H Posts: 116
    edited 2010-10-12 10:04
    I understand your code except for this part -
    rdval                   mov     value, 0-0
    
    could you explain whats happening hear?
  • Rick_HRick_H Posts: 116
    edited 2010-10-12 10:07
    ahh it just makes the LSByte 0 so their is nothing else in the way of the movs data being written to it correct?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-12 10:25
    The "0-0" is just a placeholder. By convention, it indicates that the instruction field is something that will be modified. You could use anything you want there.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-10-12 11:27
    As Mike points out, 0-0 is just a convention for indicating a value (or, as in this case, an instruction) that will be modified externally. You can see it used in the destination field in this routine (compliment of read):
    ' basepntr = address of array/table
    ' idx = index of element to write
    ' value = value to write
    
    write                   mov     tmp1, basepntr
                            add     tmp1, idx
                            movd    wrval, tmp1
                            nop
    wrval                   mov     0-0, value
    write_ret               ret
    
  • ericballericball Posts: 774
    edited 2010-10-12 13:27
    Rick_H wrote: »
    The more I look at asm the dumber I feel. I am so used to thinking about Code as just a syntax but asm is just binary registers. Hopefully I can wrap my brain around it some more without destroying my illusion of how processors work lmao.

    In PASM code is data. Not only does code occupy the same RAM as "local variables", but there are instructions specifically for changing the source and destination registers (MOVS & MOVD). It is also possible to use ALU operations (i.e. ADD, SUB) on instructions to change the source and destination registers. Heck, just look at how JMPRET (the real instruction used for CALL & RET) works under the covers.
  • Rick_HRick_H Posts: 116
    edited 2010-10-13 07:48
    Thanks Jonnymac this works perfectly
    write                   mov     tmp1, basepntr1
                             mov     tmp2, basepntr2
                             mov     tmp3, basepntr3
                            add     tmp1, idx
                            add     tmp2, idx
                            add     tmp3, idx
                            movs    wrval1, tmp1
                            movs    wrval2, tmp2
                            movs    wrval3, tmp3
    wrval1                   mov     Value1, 0-0
    wrval2                   mov     Value2, 0-0
    wrval3                   mov     Value3, 0-0
    write_ret               ret
    

    Eric, ya I am seeing this kind of code for the first time, I have always been a High Level programer. I started with GWBasic on an old TI back in the 80's but never got a chance to do Micro programing. Tolken ring style was wher I started and then when OOP came about I was all over that in Basic 6.0. I'm also a PLC programmer and I do some robotics in a java style language for ABB. Industrial Controls was always my interest untill someone showed me a PLC based off the Basic Stamp, and then I was all over Mico Programing. I find it fasinating to program at this level without needing much hardware.
Sign In or Register to comment.