CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ASM code acces high byte

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Joost van Eenbergen
Guest







ASM code acces high byte
PostPosted: Wed Aug 13, 2003 1:28 am     Reply with quote

how can i access the MSB (high byte) of a 16 but value in asm

example

void test_routine(BYTE count, WORD value)
{
FSR0 = 0x100
#asm
loop:
movff LSB(value), POSTINC0
movff MSB(value), PORTINC0
decfsnz count
goto loop
}

joost
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516938
R.J.Hamlett
Guest







Re: ASM code acces high byte
PostPosted: Wed Aug 13, 2003 4:05 am     Reply with quote

:=how can i access the MSB (high byte) of a 16 but value in asm
:=
:=example
:=
:=void test_routine(BYTE count, WORD value)
:={
:= FSR0 = 0x100
:=#asm
:=loop:
:= movff LSB(value), POSTINC0
:= movff MSB(value), PORTINC0
:= decfsnz count
:= goto loop
:=}
:=
:=joost

movff value,POSTINC0
movff &value+1,PORTINC0

It is s sort of 'hybrid' C/ASM syntax...

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516940
Joost van Eenbergen
Guest







Re: ASM code acces high byte
PostPosted: Wed Aug 13, 2003 1:12 pm     Reply with quote

no doesn't work

any other ideas?


:=:=how can i access the MSB (high byte) of a 16 but value in asm
:=:=
:=:=example
:=:=
:=:=void test_routine(BYTE count, WORD value)
:=:={
:=:= FSR0 = 0x100
:=:=#asm
:=:=loop:
:=:= movff LSB(value), POSTINC0
:=:= movff MSB(value), PORTINC0
:=:= decfsnz count
:=:= goto loop
:=:=}
:=:=
:=:=joost
:=
:=movff value,POSTINC0
:=movff &value+1,PORTINC0
:=
:=It is s sort of 'hybrid' C/ASM syntax...
:=
:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516946
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

Re: ASM code acces high byte
PostPosted: Wed Aug 13, 2003 1:49 pm     Reply with quote

:=:=how can i access the MSB (high byte) of a 16 but value in asm
:=:=
:=:=example
:=:=
:=:=void test_routine(BYTE count, WORD value)
:=:={
:=:= FSR0 = 0x100
:=:=#asm
:=:=loop:
:=:= movff LSB(value), POSTINC0
:=:= movff MSB(value), PORTINC0
:=:= decfsnz count
:=:= goto loop
:=:=}
:=:=
:=:=joost
:=
:=movff value,POSTINC0
:=movff &value+1,PORTINC0
:=
:=It is s sort of 'hybrid' C/ASM syntax...
:=
:=Best Wishes
I know this is for an 18 part but under the ASM for the 12/14 parts there was MOVPLW label and MOVPHW label for the low and the high parts of the 16 bit variable label. I wonder why MOVPLW and MOVPHW are missing in the 18F ASM documentation?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516947
R.J.Hamlett
Guest







Re: ASM code acces high byte
PostPosted: Wed Aug 13, 2003 2:43 pm     Reply with quote

:=:=:=how can i access the MSB (high byte) of a 16 but value in asm
:=:=:=
:=:=:=example
:=:=:=
:=:=:=void test_routine(BYTE count, WORD value)
:=:=:={
:=:=:= FSR0 = 0x100
:=:=:=#asm
:=:=:=loop:
:=:=:= movff LSB(value), POSTINC0
:=:=:= movff MSB(value), PORTINC0
:=:=:= decfsnz count
:=:=:= goto loop
:=:=:=}
:=:=:=
:=:=:=joost
:=:=
:=:=movff value,POSTINC0
:=:=movff &value+1,PORTINC0
:=:=
:=:=It is s sort of 'hybrid' C/ASM syntax...
:=:=
:=:=Best Wishes
:=I know this is for an 18 part but under the ASM for the 12/14 parts there was MOVPLW label and MOVPHW label for the low and the high parts of the 16 bit variable label. I wonder why MOVPLW and MOVPHW are missing in the 18F ASM documentation?

Because the assembler, is not the normal MPLAB assembler. If you want the high byte of a label (as opposed to it's contents), then you can use the normal 'C' mask and rotation syntaxes. The version shown above is for the contents of the label, and does work on both the 14bit, and 16bit parts (I originally used it on the 16F family...). The poster has to be using 18x parts, since they are using the 'movff' syntax that only applies to these.

Can I suggest to the original poster, if it still doesn't work after noting the comments below, posts a better example, showing what they actually want to do, with details of the chip involved, and 'test' values that they are trying to transfer (and definitions) since this should work. However the code as given, makes little sense. The following comments apply:
1) The 'point' about the 'postinc0' register, is that it should automatically increment the target, after each transfer, but the address has to allready be set up in FSR0L, and FSR0H, before doing this. Though 'FSR0', is shown being set to 0x100, unless this is defined as a 'long', only one byte will be transferred in the initialisation...
2) Also then the code shows the second byte being moved to a different register name (when it should go to the same register). Beware also, that if you once use the FSR registers, you must ensure that the interrupt code will save these, or ensure that interrupts are disabled when you use the registers.
3) Note also that 'WORD', is not a CCS default definition. If this is not being set to int16, the code will not work.
4) Finally, the example, shows 'value', as being a WORD, and not the _address_ of a WORD. As such, this will be a _local_ variable to the 'test_routine' function, and will never change the original memory addressed by the 'value' in the main code. If you want to change the memory where this is stored, you have to pass the _address_ of the variable, and not the contents (this is standard 'C'). I suspect this is what is failing...

As an example, the following is a simple 'memcpy' routine, designed to work equally well if called from inside an interrupt handler, or outside, and works fine. The basic syntax shows how the functions work. Note that the interrupts are disabled, if the routine is called with interrupts enabled:

#bit GIE = 0xFF2.7
#byte POSTINC0 = 0xFEE
#byte POSTINC1 = 0xFE6
#byte FSR0H = 0xFEA
#byte FSR0L = 0xFE9
#byte FSR1H = 0xFE2
#byte FSR1L = 0xFE1

//Replacement for the memcpy routine, including interrupt protection
#inline
void mymemcpy(char *dest,char *source, int num)
{
if (GIE)
{
disable_interrupts(GLOBAL);
#ASM
MOVFF dest,FSR0L
MOVFF &dest+1,FSR0H
MOVFF SOURCE,FSR1L
MOVFF &source+1,FSR1H
LOOP:
MOVFF POSTINC1,POSTINC0
DECFSZ num
GOTO LOOP
#ENDASM
enable_interrupts(GLOBAL);
}
else
{
#ASM
MOVFF dest,FSR0L
MOVFF &dest+1,FSR0H
MOVFF SOURCE,FSR1L
MOVFF &source+1,FSR1H
LOOP1:
MOVFF POSTINC1,POSTINC0
DECFSZ num
GOTO LOOP1
#ENDASM
}
}

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516948
Freud
Guest







Re: ASM code acces high byte
PostPosted: Wed Aug 13, 2003 3:30 pm     Reply with quote

Hi,

Do you try to use HIGH and LOW directives ?
For instance with the value 0x1234 :
HIGH(0x1234) will give 0x12
LOW(0x1234) will give 0x34

However, I don't know if it works with variables.

Regards,
David


:=:=how can i access the MSB (high byte) of a 16 but value in asm
:=:=
:=:=example
:=:=
:=:=void test_routine(BYTE count, WORD value)
:=:={
:=:= FSR0 = 0x100
:=:=#asm
:=:=loop:
:=:= movff LSB(value), POSTINC0
:=:= movff MSB(value), PORTINC0
:=:= decfsnz count
:=:= goto loop
:=:=}
:=:=
:=:=joost
:=
:=movff value,POSTINC0
:=movff &value+1,PORTINC0
:=
:=It is s sort of 'hybrid' C/ASM syntax...
:=
:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516950
Joost van Eenbergen
Guest







Re: ASM code acces high byte
PostPosted: Thu Aug 14, 2003 2:38 am     Reply with quote

Sorry but your code does work.

i directly copy/paste your code. but there was a typo in it. so thats why it didn't work

anyhow thanx alot

:=:=how can i access the MSB (high byte) of a 16 but value in asm
:=:=
:=:=example
:=:=
:=:=void test_routine(BYTE count, WORD value)
:=:={
:=:= FSR0 = 0x100
:=:=#asm
:=:=loop:
:=:= movff LSB(value), POSTINC0
:=:= movff MSB(value), PORTINC0
:=:= decfsnz count
:=:= goto loop
:=:=}
:=:=
:=:=joost
:=
:=movff value,POSTINC0
:=movff &value+1,PORTINC0
:=
:=It is s sort of 'hybrid' C/ASM syntax...
:=
:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516957
R.J.Hamlett
Guest







Re: ASM code acces high byte
PostPosted: Thu Aug 14, 2003 4:16 am     Reply with quote

:=Sorry but your code does work.
:=
:=i directly copy/paste your code. but there was a typo in it. so thats why it didn't work
:=
:=anyhow thanx alot
Yes. This code won't work (if you read my full reply posted afterwards, you will see that there are two solid reasons, and two other possible reasons...). However these are based on the faults allready present in your code (the fact that you are trying to change the bytes in a local variable, not the one from the calling program, is the 'primary' one), then followed by the use use of 'POSTINC0', and 'PORTINC0', which are directly copied from your code, where you are either trying to do something 'ingenious', by accessing another register, or have a typo in your incoming code.

Since all I posted was the technique by which you access the second byte of a register (which was the question asked...), I would not expect it to work until the rest of the code is debugged. However what is posted, _is_ the technique to answer the question asked.

Best Wishes

:=:=:=how can i access the MSB (high byte) of a 16 but value in asm
:=:=:=
:=:=:=example
:=:=:=
:=:=:=void test_routine(BYTE count, WORD value)
:=:=:={
:=:=:= FSR0 = 0x100
:=:=:=#asm
:=:=:=loop:
:=:=:= movff LSB(value), POSTINC0
:=:=:= movff MSB(value), PORTINC0
:=:=:= decfsnz count
:=:=:= goto loop
:=:=:=}
:=:=:=
:=:=:=joost
:=:=
:=:=movff value,POSTINC0
:=:=movff &value+1,PORTINC0
:=:=
:=:=It is s sort of 'hybrid' C/ASM syntax...
:=:=
:=:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516958
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group