asm not making sense

This is a discussion on asm not making sense within the Tech Board forums, part of the Community Boards category; So I've disassembled a project (PIC16F887), which has this snippet: Code: 0x009C 0x081E MOVF ADRESH, 0 0x009D 0x00F1 MOVWF R0+1 ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,678

    asm not making sense

    So I've disassembled a project (PIC16F887), which has this snippet:
    Code:
    0x009C        0x081E              MOVF       ADRESH, 0
    0x009D        0x00F1              MOVWF      R0+1
    0x009E        0x01F0              CLRF       R0
    0x009F        0x1683              BSF        STATUS, 5
    0x00A0        0x081E              MOVF       ADRESL, 0
    0x00A1        0x04F0              IORWF      R0, 1
    0x00A2        0x3000              MOVLW      0
    0x00A3        0x04F1              IORWF      R0+1, 1
    0x00A4        0x0008              RETURN
    (Non-bold for context)
    The manual states this about MOVLW:
    The eight-bit literal ‘k’ is loaded into
    W register. The “don’t cares” will
    assemble as ‘0’s.
    And this about IORWF:
    Inclusive OR the W register with
    register ‘f’. If ‘d’ is ‘0’, the result is
    placed in the W register. If ‘d’ is
    ‘1’, the result is placed back in
    register ‘f’.
    (My source)
    So, to my understanding, these 2 instructions would result in C code that looks round-about something like
    Code:
    R0+1 |= 0;
    And I have to say, that it doesn't make any sense at all why someone would do this. (Note that this is from an optimized library.)

    Am I perhaps reading this wrong?

    Thanks

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    What does the syntax "R0+1" mean? I doubt it means "The value in R0, plus 1".
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,678
    I assumed it was actually an address (of course, I'm no asm guru, and could be very wrong)
    That is, "R0+1" is "R1" or something.
    I guess this because, I know in PICs, system registers/variables are simply defs to fixed addresses, so it would make sense that if R0 is already just a pointer or equivalent, adding 1 would be valid.

    EDIT: Okay, yeah that looks like that's the deal. Before the 2 instructions in question, ADRESL and ADRESH get put into R0 and R0+1, respectively. The 'L' and 'H' stand for low and high bytes.
    Last edited by Yarin; 03-29-2011 at 03:46 PM.

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,678
    As it turns out, leaving those instructions out of the new code didn't effect anything (that I can tell). I'm still really confused why those would even be in there, especially since it works fine without them.
    Anyway, thanks for the response.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  3. Beginning ASM.
    By Krak in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2004, 06:27 PM
  4. Making control...
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2004, 02:42 PM
  5. Asm + C++
    By JaWiB in forum C++ Programming
    Replies: 17
    Last Post: 06-26-2003, 04:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21