How to do this in ASM?


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429

    Default How to do this in ASM?

    Can someone tell me how I could write assembly that does the same as the following line would in PBP:

    array[index]=my_data.Byte0

    assuming that the variables are already declared as follows:

    array VAR BYTE[12]
    index VAR BYTE
    my_data VAR WORD

    I was trying to work out an ASM equiv but came up empty.

    *edit* Its for a 16F84A
    Last edited by Kamikaze47; - 18th November 2005 at 22:33.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    14 or 16bit core ??
    <br>
    DT

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Sorry... its for a 16F84A

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Untested, off the top of my head. At least the F84 makes it easy, with only 1 bank of RAM
    Code:
    ASM
        movlw   low _array   ; load FSR with address of the array
        movwf   FSR
        rlf     _index,W     ; mult. index * 2 since array is WORDs
        addwf   FSR, F       ; add result to FSR
        movf    INDF, W      ; get the LowByte
        movwf   _my_data
        incf    FSR, F       ; point to next byte
        movf    INDF, W      ; get the HighByte
        movwf   _my_data + 1
    ENDASM
    <br>
    DT

  5. #5
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    i think thats the reverse of what i want, ie: my_data.Byte0=array[index]

    but i think im getting the idea... a couple of questions tho..

    i take it "low" infront of a veriable gives its memory address?

    and how does this FSR thing work? ive never had to use it before.

    Thanks

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    yup, you're right, it's backwards. That's what I get for trying to squeez in a reply when the boss isn't looking.

    low is like LowByte or Byte0 in PBP, it just gives the lowest 8-bits of a value.

    And, the FSR allows you to Read/Write the value of any RAM location by placing the address of the desired byte in the FSR register, and then reading/writing to/from the INDF register.

    It's kind of like using PEEK and POKE in PBP.

    It sounds like you might be able to take it from there, but if not let me know, and I'd make it work the other way around when I get off work.
    <br>
    DT

  7. #7
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Im needing to do this becuase im writing a pbp program that has interrupts that are required to be written in ASM.

    If I declare a variable in pbp as a word, e.g. my_data VAR WORD, can I then use the variable _my_data in ASM as is?

    for example, can i do rrf _my_data,1 and expect the whole word to be rotated?

  8. #8
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    The only other thing I dont get is how to get the base memory address of the array. Looking at your code here and the comment, i cant see how its doing what the comment said it does:

    movlw low _array ; load FSR with address of the array
    movwf FSR

    Thanks for ur help

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    >> can i do rrf _my_data,1 and expect the whole word to be rotated?

    No, it only works with 1 byte at a time. But, the rrf rotates through the CARRY flag, so a second rrf on the next byte will rotate the CARRY right into the next byte.

    >> I dont get is how to get the base memory address of the array

    At the ASM level, that's what variables are, pointers(address) to the actual memory location in RAM. So low _array gives you the lowbyte of the address of the variable array.
    <br>
    DT

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Kamikaze,

    Ok, let's try this one more time. I think this is what you're after. And, since you're using it in an interrupt, it save/restores the FSR so it doesn't interfere with normal PBP operations.
    Code:
    fsave var byte
    ASM
        movf    FSR, W       ; save current FSR value
        movwf   _fsave
        movlw   low _array   ; load FSR with address of the array
        movwf   FSR
        movf    _index,W     ; get index value
        addwf   FSR, F       ; add index to FSR
        movf    _my_data, W  ; get my_data.Byte0
        movwf   INDF         ; put it in the array
        movf    _fsave, W    ; restore the original FSR
        movwf   FSR
    ENDASM
    DT

  11. #11
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Thanks for that Darrel... Looks like it will do what I want

Similar Threads

  1. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  2. ASM help
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 21st October 2009, 03:08
  3. ASM or PBP First?
    By mackrackit in forum Off Topic
    Replies: 4
    Last Post: - 10th October 2009, 12:08
  4. Serial Output - for an ASM numb
    By scomi85 in forum Serial
    Replies: 0
    Last Post: - 1st March 2009, 10:13
  5. Problem using ASM instruction
    By ewandeur in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd April 2008, 15:26

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts