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
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
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 )
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?
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.
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.
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