assembly programming help - pic16

Thread Starter

nathan.petrelli.1987

Joined Jun 12, 2008
3
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 :)
 

Mark44

Joined Nov 26, 2007
628
Nathan,
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.
 

RiJoRI

Joined Aug 15, 2007
536
is it possible that no one knows how to solve this thing? :(
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.

--Rich
 

Thread Starter

nathan.petrelli.1987

Joined Jun 12, 2008
3
Nathan,
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.
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

org 0
goto MAIN

MAIN: movlw 0x32
addwf 0x22
addwf 0x23
movwf 0x24

END
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.

V1 EQU 0x32
V2 EQU 0xB1
RES EQU 0x35

org 0
goto MAIN

MAIN: % here i should put some condition which i dont know how to
movlw V1
subwf V2
movwf RES
% if not true

goto LAB1

LAB1: movlw V1
addwf V2
movwf RES

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

RiJoRI

Joined Aug 15, 2007
536
2. Write a program which reads the data 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
Rich (BB code):
 org 0
goto MAIN         ; This is not really needed.

MAIN: 
    movlw 0x32    ; Move a literal Value into W
    addwf 0x22    ; Add the contents in address 22
    addwf 0x23    ; Add the contents in address 23
    movwf 0x24   ;  Move W to address 24
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?



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
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
;ENDIF

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:

HTH,
--Rich
 
Top