assembly programming help - pic16

Discussion in 'Programmer's Corner' started by nathan.petrelli.1987, Jun 12, 2008.

  1. nathan.petrelli.1987

    Thread Starter New Member

    Jun 12, 2008
    hi guys,

    im having a problem with my homework regarding assembly, to be more precise, programming for the microchip pic16 series. heres the thing, im really a noob and i dont figure it out at all, i have this homework so please if someone knows to solve it or if someone can give me some help. i also need to ask you how can i assemble these codes? using winasm?

    1. write a program which defines name V1 for the location 0x32, V2 for the location 0xB1, RES for the location 0x35. program substracts V2 from V1 if V1>V2 and stores the result in RES, else (if V1<=V2) is adds V2 TO V1 and stores and stores it into RES

    2. Write a program which reads the date from the location 0x32 into register W, adds to it the value from the location 0x22 and 0x23 and stores the result into location 0x24

    so, those are the problems so if someone is capable, please help me

    thanks in forward, and sincere greetings

    ps. data sheet can be found here :)
  2. nathan.petrelli.1987

    Thread Starter New Member

    Jun 12, 2008
    is it possible that no one knows how to solve this thing? :(
  3. Mark44

    Well-Known Member

    Nov 26, 2007
    You're not likely to get any help here without at least attempting to write some code. It's a policy on this forum (and many others) that we don't do homework problems. If you take a stab at it and things don't work, we're very happy to help you out, but not until we see that you've taken the first step.
  4. RiJoRI

    Well-Known Member

    Aug 15, 2007
    Nah, we got real jobs, and this is relatively easy. (Or maybe some people are asleep!)

    First, are you familiar with any other language -- e.g., BASIC, C, Pascal? It can be easier to learn assembler if you have knowledge of another language.

    Next, variable declaration is dependent on the assembler you use. I am not very familiar with the PIC opcodes, but if you study them, along with the definitions of how to load registers (uChip calls them "files"), you will start to see what's happening. Sorry, but there is no quick and easy way to learn this stuff. On the other hand, once you know one chip's opcodes you can apply it to other chips. For instance, "MOV A,#00", "LDA #00", and "LD A,#00.B" are all commands to load zero into the accumulator -- which is like the W file in PIC-world.

  5. nathan.petrelli.1987

    Thread Starter New Member

    Jun 12, 2008
    i solve some of it but i dunno how to check whether its correct or not. thats why i didnt put any of my codes but ok, here´ how i did the second one but im definitely sure that its not correct cause i really dont understand

    im not sure whether we have these opcodes, can we put this as a operand to movlw or whether i should have used movf

    the second one i just did the outer wraper, i dont know how to do conditional coding in assembly, its really difficult and sincerely he didnt mention it.

    so i hope that someone can help me know because i really want to solve this thing. thanks in forward
  6. RiJoRI

    Well-Known Member

    Aug 15, 2007
    Code ( (Unknown Language)):
    1.  org 0
    2. goto MAIN         ; This is not really needed.
    4. MAIN:
    5.     movlw 0x32    ; Move a literal Value into W
    6.     addwf 0x22    ; Add the contents in address 22
    7.     addwf 0x23    ; Add the contents in address 23
    8.     movwf 0x24   ;  Move W to address 24
    9. END
    The first three instructions are incomplete. You need the destination code for them. E.g., movwf 0x32,0 moves data from File32 to the Working File; movwf 0x32,1 moves data from the Working File to File32.
    Also the first instruction is incorrect. Do you see what it is doing?

    What helps me is breaking down the requirements into steps.
    ;define names:
    ; V1 for the location 0x32,
    ; V2 for the location 0xB1,
    ; RES for the location 0x35.

    Then re-arrange the next part into an IF-THEN-ELSE-ENDIF form
    ;IF V1>V2 THEN
    ; subtract V2 from V1
    ; store the result in RES
    ;ELSE (V1<=V2)
    ; add V2 TO V1
    ; store it into RES

    Note that > is the complement of <=. That is, "NOT-GREATER-THAN" is the same as "LESS-THAN-OR-EQUAL". This will save us a second test. Also, the only way to do a comparison with this chip is to do a subtraction, and test the Carry and Zero flags :eek: