Maker Pro
Maker Pro

Weird MPASM stuff?

A

Active8

Jan 1, 1970
0
hi:

sorry again. same prob at .piclist group. it's no wonder this group is
so busy. the collective knowlege is all here.

i don't remember having this prob with the MPLAB IDE i downloaded years
ago.

PIC16F84A

with MPLAB 6.3 MPASM i tried to do the following:

W starts off containing 0x04 in all these code frags

incf W, W ; or
incf W, 0 ; changes the contents of W to 0x01

incf W ; leaves it at 0x04

i thought leaving the 2nd operand out defaulted to 0 i.e., W. maybe not
when it's a file op. eh?

decf W ; doesn't do squat and
decf W, W ; leaves 0xff in W - cute

so to do 4 - 1 = 3 ...

sublw 1 ; which is 0xfd
movwf mulcnd
comf mulcnd
movf mulcnd, W
addlw 1 ; W = 3

because
sublw 1 ; 0xfd or b'11111101'
comf W, W ; gives b'11111111' ?!!!

is this a simulator bug or real life? chip is PIC16f84a

i also did one of those table lookup deals with

LOOKUP
addwf PCL, F
MSGS DT "ABCD"
DT "EFGH"

this is why i need to decrement W. it looks like when i add to the
program counter, it ends up too high by 1. it's incrementing after the
addwf op, right?

thanks in advance for squaring me away.

mike
 
H

Howard Henry Schlunder

Jan 1, 1970
0
The Working register is not a normal register. You cannot use it unless the
instruction specifically was designed to use it. In other words:

W is defined as 0, so:

incf W, W ; or

will result in grabbing the value from the Indirect File's register, which
is to say it will read the value from the FSR register, move to the address
pointed to by the FSR contents, and then obtain that value and increment it,
finally storing the result in the W. The result comes from lala-land as you
are seeing.

The proper way to increment the W is to use the "Add Literal to W"
instruction:

addlw 1

Other operations, like bit rotations and complement operations on the W must
be done as a two step procedure:

movwf SomeTemporaryRegister
comf SomeTemporaryRegister, W

There are many caveats to implementing table reads. Although I don't know
what your code does, I would highly recommend using the example code in App
Note 556, Implementing a Table Read: [
http://www.microchip.com/1010/suppdoc/appnote/all/an556/index.htm ].

Howard Henry Schlunder

in message
news:[email protected]...
 
A

Active8

Jan 1, 1970
0
The Working register is not a normal register. You cannot use it unless the
instruction specifically was designed to use it. In other words:

W is defined as 0, so:

incf W, W ; or

will result in grabbing the value from the Indirect File's register, which
is to say it will read the value from the FSR register, move to the address
pointed to by the FSR contents, and then obtain that value and increment it,
finally storing the result in the W. The result comes from lala-land as you
are seeing.

aw hell, i should've realized that.
The proper way to increment the W is to use the "Add Literal to W"
instruction:

addlw 1

and a decf on a temp reg will save me 2 instructions compared to the 2's
compliment crap.
Other operations, like bit rotations and complement operations on the W must
be done as a two step procedure:

movwf SomeTemporaryRegister
comf SomeTemporaryRegister, W

There are many caveats to implementing table reads. Although I don't know
what your code does, I would highly recommend using the example code in App
Note 556, Implementing a Table Read: [
http://www.microchip.com/1010/suppdoc/appnote/all/an556/index.htm ].

ok, i'll check it out. thanks for the full link.

brs,
mike
 
J

Jan-Erik Söderholm

Jan 1, 1970
0
A

Active8

Jan 1, 1970
0
Howard said:
There are many caveats to implementing table reads. Although I don't know
what your code does, I would highly recommend using the example code in App
Note 556, Implementing a Table Read: [
http://www.microchip.com/1010/suppdoc/appnote/all/an556/index.htm ].

Which has code examples that are brooken...
Details has been posted to PIClist mailing list (which is highly
recomended, b.t.w,
see www.piclist.com).

Jan-Erik.
ah. thanks. someone said the PIClist was helpful but didn't specify the
mailing list.

i noticed that alot of code e.g.s (ANs and other) had errors, but saw
through them. the table lookup AN did at least warn me of the page
boundary prob. i think my code prob was just a matter of accounting for
the extra PCL increment after i load in the offset. not sure yet, i have
to try.

is there anyway to subscribe to the mailing list without getting
inundated with every post that gets sent to POClist.

brs,
mike
 
J

Jan-Erik Söderholm

Jan 1, 1970
0
Active8 said:
i noticed that alot of code e.g.s (ANs and other) had errors, but saw
through them. the table lookup AN did at least warn me of the page
boundary prob.

Yes, but the *real* problem in AN556, is that example 3,4 and 5 (I
think) has
an incorrect calculation of the "Calculated-GOTO" that will get the
code into an infinite loop if called with 0 (zero) as the "index"...
i think my code prob was just a matter of accounting for
the extra PCL increment after i load in the offset. not sure yet, i have
to try.

That kind of sounds as the bug in the AN556, not sure...
is there anyway to subscribe to the mailing list without getting
inundated with every post that gets sent to POClist.

You first subscribe, then send mails to the listserver with commands
specifying which "topics" you want to get. [PIC], [AVR], [EE] are some
of them. I have PIC and E and get about 20-30 mails a day.


Anyway, try it, if you don't like it, just remove yourself...

Jan-Erik.
 
A

Active8

Jan 1, 1970
0
Yes, but the *real* problem in AN556, is that example 3,4 and 5 (I
think) has
an incorrect calculation of the "Calculated-GOTO" that will get the
code into an infinite loop if called with 0 (zero) as the "index"...

can't remember. i'll look at it again. the calculated goto is a good one
so i'll have to fix the code.
That kind of sounds as the bug in the AN556, not sure...

maybe. nothing like stepping through code to make sure.
is there anyway to subscribe to the mailing list without getting
inundated with every post that gets sent to POClist.

You first subscribe, then send mails to the listserver with commands
specifying which "topics" you want to get. [PIC], [AVR], [EE] are some
of them. I have PIC and E and get about 20-30 mails a day.


Anyway, try it, if you don't like it, just remove yourself...

yeah, it looks good. i can always add filters on my end, too.

tnx,
mike
 
Top