Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Error in Assembly code for multiplying two members with rotation using PIC16F84

Status
Not open for further replies.

chancelier

Junior Member level 1
Joined
Jan 26, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
tunisia
Activity points
1,433
hi evryone
i am a newbie in assembler coding , i did a simple code of multiplying two nembers with rotation using assembler instructions of a 16F84 microcontroller but this code did not work.
i work with MPLAB
here is the code



LIST p=16F84
#include<p16F84.inc>
;declaration des variables
CBLOCK 0x00c
N1:1
N2:1
Re:2
compt:1
ENDC
movlw 8
movwf compt
movlw 0x04
movwf N1
movlw 0x05
movwf N2
movf N1,w
clrf Re
boucle rrf N2,f
btfsc STATUS,C
addwf Re,f
rrf Re,f
rrf Re+1,f
decfsz compt,f
goto boucle
END
registre file



where is the mistake?
can anyone give me an sembling tutorial?
 

Re: assembler code

I have written a small assembler generator for mid range pics to use with mplab and posted it on eda board here.



It generates assembler code for the mid range Pics for common programming constructs such as if, for, while, delay, multiply, divide, shift and limits.

Try it out and see if it helps.
Here is the code it generated for multiply variable 'temp' by 5.

Code:
;------ Variables required

mplyby  res     1       ;Multiplyer
hiRes   res     1       ;Hi byte of result
loRes   res     1       ;Lo byte of result
count   res     1       ;Bit counter

;------ Unsigned byte multiply subroutine

Mply    movlw   .5
        movwf   mplyby
        clrf    hiRes
        clrf    loRes
        movlw   .8
        movwf   count
        movf    temp,w

Mloop   rrf     mplyby,f
        skpnc
        addwf   hiRes,f
        rrf     hiRes,f
        rrf     loRes,f
        decfsz  count,f
        goto    Mloop
        return
 

    chancelier

    Points: 2
    Helpful Answer Positive Rating
Re: assembler code

Hi,

There are several good assembler tutorials around - here is one -
http://www.winpicprog.co.uk/pic_tutorial.htm

The other thing is use a more modern chip like the Pic16F628A or 16F88, the 16F84 is so last century !

Re your code - it does work ok - see the result in the jpeg - its using mplabs Sim - just single step the code and watch it work. (ignore the _CP_ON label )
 

Re: assembler code

hi
thanks for both of you
now i am using another method to do the multiply operation which uses addition operations(not rotation method like the previous code)
i remind you that i am using a 16F84 microcontroller
Code:
 ;------ Variables required 

mplyby   res     1       ;Multiplyer
hiRes     res     1       ;Hi byte of result
loRes     res     1       ;Lo byte of result
aux        res     1       ;auxilary byte

;------ Unsigned byte multiply subroutine

Mply    movlw   .5
           movwf   mplyby             ;this is the counter 
           clrf    hiRes
           clrf    loRes
           clrf    aux
           movf    temp,w

Mloop   
        addwf   loRes,f
        rlf        aux,f
        movf    aux,w
        addwf   hiRes,f                     ; to add the carry with hiRes
        clr        aux
        movf    temp,w
        decfsz  mplyby,f
        goto     Mloop
        return

this method is correct but it seems to me that there are better solutions
what do you think?
 

Re: assembler code

I agree with wp100. The 84 is a very old chip, it was the first pic micro to use flash memory. It is outdated and expensive.
There is a wide choice of Pic micros that are more cost effective and have a lot more useful peripheral modules.
Mp Sim is very good for stepping through your code to see whats happening.
If you can find a better routine for multiply, thats cool.
Writing assembler code is like solving puzzles, you have to find the most elegant solution.
Thats the way I look at it, I don't write code, I write poetry.
 

assembler code

I agree with wp100. The 84 is a very old chip, it was the first pic micro to use flash memory. It is outdated and expensive.
I agree that 16F84 is very old, but I think it's the best to start off learning assembly for PIC BECAUSE of its lack of peripherals. One can focus on the assembly part and using the few peripherals available for absolute basics and then head to 16F877 or something else or even the 18F to grasp the new peripherals and then get some serious programs going.
 

Re: assembler code

i must learn it because simply its included in our accademic curriculum and i am gonna sit for an exam on that , so i have no choice
now please give me your opinion about the code
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top