Info on assembler syntax

Started by Giampaolo Consonni September 13, 2003
I just finish ,all working as expected I guess, my first assembler
application using free Yar Software , on MSP430F1232; a simple(1,4k code)
controller for a diving lamp.
I used OLIMEX hardware prototype and works very well.
 
The problems I  face durig develop where often bad usage of assembler syntax.  I
fact I did not find a clear explanation of the rules , for example the  special
character, like # , & , define.
 
What I learn is:
# need to be place in front at numbers like : MOV.B   #001F,R6
& seems need in front on periferal register like: mov.b   #000h,&P1OUT
define.  definition of a memory location.
 
for example :
define   memory1   (0x00200)
define   memory2   (0x00201)
====================One mistake was define a number to be used in program as a
constant numeric value  instead write the number itself to make more readable
the program ,ie:
define    LAMP_MAX_POWER     (0x00F)
 
mov.b    LAMP_MAX_POWER,  LAMP_power_memory_location
 
How is possible something as above.
=======================Another think not clear, with following command
 
CMP.B   Mem_loc1,Mem_loc2
I compare the memory location address or the content, I think the content.
 
In summary , are there someone in this community that have a piece of paper
where all above simpler assembler rules and syntax are explained.
I read apps note SLAU49C but I still have these doubt in mind (may be I'm
stipud).
 
Thanks for help. Paolo.
 
 
 
 



---------------------------------
Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l'antivirus, il
filtro Anti-spam




Beginning Microcontrollers with the MSP430

Paulo, you're obviously not stupid if you got it to work! The syntax is 
confusing, and to undertsand it I recommend you read  SLAUE10B, chapters 
5 and 9 IIRC, plus have a good read of SLAA024, the applications 
reports. Chapters 6,7 & 8 contain some useful pointers on both hardware 
and software.

basically # indicates an absolute value, which includes the address for 
a CALL, or BR instruction, since BR is actually a direct modification of 
the PC, BR #DAVE is actually translated into MOV #DAVE,PC.

& inndicates absolute mode, where the value after & is the actual 
address or value. So MOV &DAVE,&FRED means move data at address DAVE to 
address FRED.

No prefix means what Ti call symbolic mode, this is similar to absolute, 
and sometimes interchangable, but not always.

MOV	DAVE,FRED translates to MOV DAVE(PC),FRED(PC).

Hence

	&P1OUT refers to the data at the adress P1OUT

	#p1OUT is the actual address of the P1OUT register

	P1OUT	depends a little upon how you declared P1OUT, but, in most cases 
will likely be the same as &P1OUT.

Al


Giampaolo Consonni wrote:

> I just finish ,all working as expected I guess, my
first assembler application using free Yar Software , on MSP430F1232; a
simple(1,4k code) controller for a diving lamp.
> I used OLIMEX hardware prototype and works very well.
>  
> The problems I  face durig develop where often bad usage of assembler
syntax.  I fact I did not find a clear explanation of the rules , for example
the  special character, like # , & , define.
>  
> What I learn is:
> # need to be place in front at numbers like : MOV.B   #001F,R6
> & seems need in front on periferal register like: mov.b  
#000h,&P1OUT
> define.  definition of a memory location.
>  
> for example :
> define   memory1   (0x00200)
> define   memory2   (0x00201)
> ====================> One mistake was define a number to be used in
program as a constant numeric value  instead write the number itself to make
more readable the program ,ie:
> define    LAMP_MAX_POWER     (0x00F)
>  
> mov.b    LAMP_MAX_POWER,  LAMP_power_memory_location
>  
> How is possible something as above.
> =======================> Another think not clear, with following command
>  
> CMP.B   Mem_loc1,Mem_loc2
> I compare the memory location address or the content, I think the content.
>  
> In summary , are there someone in this community that have a piece of paper
where all above simpler assembler rules and syntax are explained.
> I read apps note SLAU49C but I still have these doubt in mind (may be I'm
stipud).
>  
> Thanks for help. Paolo.
>  
>  
>  
>  
> 
> 
> 
> ---------------------------------
> Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l'antivirus,
il filtro Anti-spam
> 
> 
> 
> 
> 
> .
> 
>  
> 
> ">http://docs.yahoo.com/info/terms/ 
> 
> 
> 


Is like when we buy a new "electronics toy", we start play with,
before
 read all user instruction. 
I normally read user instructions, but in this case are very deep into
 documentation. I saw examples into slaa24 of wath i need i try to used 
but error messages again.Then I remember some notes regarding differencies
between TI and Yar mnemonics. 
Finally the Yar manual "MPS430 assembler,linker and librarian Programming
Giude" is wath I was looking for.
 
Thanks onestone


onestone <onestone@ones...> wrote:
Paulo, you're obviously not stupid if you got it to work! The syntax is 
confusing, and to undertsand it I recommend you read  SLAUE10B, chapters 
5 and 9 IIRC, plus have a good read of SLAA024, the applications 
reports. Chapters 6,7 & 8 contain some useful pointers on both hardware 
and software.

basically # indicates an absolute value, which includes the address for 
a CALL, or BR instruction, since BR is actually a direct modification of 
the PC, BR #DAVE is actually translated into MOV #DAVE,PC.

& inndicates absolute mode, where the value after & is the actual 
address or value. So MOV &DAVE,&FRED means move data at address DAVE to 
address FRED.

No prefix means what Ti call symbolic mode, this is similar to absolute, 
and sometimes interchangable, but not always.

MOV      DAVE,FRED translates to MOV DAVE(PC),FRED(PC).

Hence

      &P1OUT refers to the data at the adress P1OUT

      #p1OUT is the actual address of the P1OUT register

      P1OUT      depends a little upon how you declared P1OUT, but, in most
cases 
will likely be the same as &P1OUT.

Al


Giampaolo Consonni wrote:

> I just finish ,all working as expected I guess, my
first assembler application using free Yar Software , on MSP430F1232; a
simple(1,4k code) controller for a diving lamp.
> I used OLIMEX hardware prototype and works very well.
>  
> The problems I  face durig develop where often bad usage of assembler
syntax.  I fact I did not find a clear explanation of the rules , for example
the  special character, like # , & , define.
>  
> What I learn is:
> # need to be place in front at numbers like : MOV.B   #001F,R6
> & seems need in front on periferal register like: mov.b  
#000h,&P1OUT
> define.  definition of a memory location.
>  
> for example :
> define   memory1   (0x00200)
> define   memory2   (0x00201)
> ====================> One mistake was define a number to be used in
program as a constant numeric value  instead write the number itself to make
more readable the program ,ie:
> define    LAMP_MAX_POWER     (0x00F)
>  
> mov.b    LAMP_MAX_POWER,  LAMP_power_memory_location
>  
> How is possible something as above.
> =======================> Another think not clear, with following command
>  
> CMP.B   Mem_loc1,Mem_loc2
> I compare the memory location address or the content, I think the content.
>  
> In summary , are there someone in this community that have a piece of paper
where all above simpler assembler rules and syntax are explained.
> I read apps note SLAU49C but I still have these doubt in mind (may be I'm
stipud).
>  
> Thanks for help. Paolo.
>  
>  
>  
>  
> 
> 
> 
> ---------------------------------
> Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l'antivirus,
il filtro Anti-spam
> 
> 
> 
> 
> 
> .
> 
>  
> 
> ">http://docs.yahoo.com/info/terms/ 
> 
> 
> 



var lrec_target="_top"; var lrec_URL = new Array(); lrec_URL[1] =
"http://rd.yahoo.com/M%6694.3867555.5111023.1261774/D=egroupweb/S05005378:HM/A50639/R=0/id=flashurl/SIGfl5bu29/*http://webevents.yahoo.com/universal/rundown/";
var link="javascript:LRECopenWindow(1)"; var lrec_flashfile =
'http://us.a1.yimg.com/us.yimg.com/a/un/universal/rundown_300x250.swf?clickTAG='+link+'';
var lrec_altURL =
"http://rd.yahoo.com/M%6694.3867555.5111023.1261774/D=egroupweb/S05005378:HM/A50639/R=1/id=altimgurl/SIGfl5bu29/*http://webevents.yahoo.com/universal/rundown/";
var lrec_altimg =
"http://us.a1.yimg.com/us.yimg.com/a/un/universal/rundown_300x250.jpg";
var lrec_width = 300; var lrec_height = 250; 
.



 



---------------------------------
Yahoo! Mail: 6MB di spazio gratuito, 30MB per i tuoi allegati, l'antivirus, il
filtro Anti-spam




Giampaolo:

I think the things you mentioned are really confusing too!

> define    LAMP_MAX_POWER     (0x00F)
> mov.b    LAMP_MAX_POWER,  LAMP_power_memory_location
> How is possible something as above.

You would need to write:

            mov.b    #LAMP_MAX_POWER,LAMP_power_memory_location


> Another think not clear, with following command
> CMP.B   Mem_loc1,Mem_loc2
> I compare the memory location address or the content, I think
> the content.

Yes.  My understanding so far is if you're using simple equates to define
labels it ends up being generally:  # says the label is a literal (just a
number).  You place it in front of a symbol which represents a number but
and also in front of a number.  Without it is assumed to be an address
reference.  Except in the case of Call where you would need it when
referring to section and sub labels.  & for fixed addresses like peripheral
registers.  Leave it off when letting the assembler decide what the actual
address is (tables, etc).

A comparison of the two modes you mentioned might be:

PowerUp	cmp.b    #LAMP_MAX_POWER,last_power_level
		jlo	   Restore
		jne      Default
Restore     mov.b    last_power_level,Rpass1
		jmp      DonePU
Default	mov.b    DefaultBrightness,Rpass1
DonePU      call     #SetLevel
            .......

Brighten    cmp.b    #LAMP_MAX_POWER,current_power_level
            jeq      Done
		mov.b    current_power_level,last_power_level
		incr.b   current_power_level
		mov.b    current_power_level,Rass1
            call     #SetLevel
Done       	.......
            ret

etc.


> I read apps note SLAU49C but I still have these
doubt in mind
> (may be I'm stipud).

No, unless we both are ;)  I find the TI documentation very confusing.
I've still got a lot to learn and it's slow going.  I spend an awful lot of
time reading the addressing modes description and the instruction set
summary, over and over again, while programming.  It's a lot easier to just
program in C, but I'm stubborn and I need to really understand this.

Beyond studying example programs, another way I get some clues about syntax
is to study the assembly output of the compiler (even if you want to
program in assembly you could write code fragments in C periodically to see
exactly how the syntax is applied to a generate a particular outcome).

I'm waiting for an in-depth primer on the instruction set, especially
addressing modes, with complete explanations of where, why and how each is
used, and where they are used differently with different instructions, and
why, and many well-explained examples.

--Bruce



Bruce Cannon wrote:
> Giampaolo:
> 
> I think the things you mentioned are really confusing too!
> 
> 
>>define    LAMP_MAX_POWER     (0x00F)
>>mov.b    LAMP_MAX_POWER,  LAMP_power_memory_location
>>How is possible something as above.
> 
> 
> You would need to write:
> 
>             mov.b    #LAMP_MAX_POWER,LAMP_power_memory_location
> 
> 
> 
>>Another think not clear, with following command
>>CMP.B   Mem_loc1,Mem_loc2
>>I compare the memory location address or the content, I think
>>the content.
> 
> 
> Yes.  My understanding so far is if you're using simple equates to define
> labels it ends up being generally:  # says the label is a literal (just a
> number).  You place it in front of a symbol which represents a number but
> and also in front of a number.  Without it is assumed to be an address
> reference.  Except in the case of Call where you would need it when
> referring to section and sub labels.  & for fixed addresses like
peripheral
> registers.  Leave it off when letting the assembler decide what the actual
> address is (tables, etc).
> 
> A comparison of the two modes you mentioned might be:
> 
> PowerUp	cmp.b    #LAMP_MAX_POWER,last_power_level
> 		jlo	   Restore
> 		jne      Default
> Restore     mov.b    last_power_level,Rpass1
> 		jmp      DonePU
> Default	mov.b    DefaultBrightness,Rpass1
> DonePU      call     #SetLevel
>             .......
> 
> Brighten    cmp.b    #LAMP_MAX_POWER,current_power_level
>             jeq      Done
> 		mov.b    current_power_level,last_power_level
> 		incr.b   current_power_level
> 		mov.b    current_power_level,Rass1
>             call     #SetLevel
> Done       	.......
>             ret
> 
> etc.
> 
> 
> 
>>I read apps note SLAU49C but I still have these doubt in mind
>>(may be I'm stipud).
> 
> 
> No, unless we both are ;)  I find the TI documentation very confusing.
> I've still got a lot to learn and it's slow going.  I spend an awful lot of
> time reading the addressing modes description and the instruction set
> summary, over and over again, while programming.  It's a lot easier to just
> program in C, but I'm stubborn and I need to really understand this.

Ti's documentation is quite clear. It's just not all in one convenient 
place. It's scattered throughout several documents. Easier in C? After 
all the confusion that we seem to have here about in line assembler, how 
to fix the position of this or that, and especially those embedded C 
jewels where, of course ANSI C was not designed for embedded systems, so 
each compiler writer gets to decide what extras they put in, and how 
they handle the embedded worlds non-standard necessities. It doesn't 
even look right to me. ;@}

> 
> Beyond studying example programs, another way I get some clues about syntax
> is to study the assembly output of the compiler (even if you want to
> program in assembly you could write code fragments in C periodically to see
> exactly how the syntax is applied to a generate a particular outcome).
> 
> I'm waiting for an in-depth primer on the instruction set, especially
> addressing modes, with complete explanations of where, why and how each is
> used, and where they are used differently with different instructions, and
> why, and many well-explained examples.

Doesn't the new book by Chris? Nagy cover that?

Al


Think of it as C. # means "The immediate number" or "the
address of". In 
fact when used by the CALL instruction:-

	CALL	#DO_THIS
	...
	...
DO_THIS:
	MOV	R4,R5
	RET

It means the literal value of DO_THIS, which is the address of the 
label. If written:-

	CALL	DO_THIS

It means call the address contained at the label DO_THIS. No different 
to C pointers really,

aL

Bruce Cannon wrote:

> Giampaolo:
> 
> I think the things you mentioned are really confusing too!
> 
> 
>>define    LAMP_MAX_POWER     (0x00F)
>>mov.b    LAMP_MAX_POWER,  LAMP_power_memory_location
>>How is possible something as above.
> 
> 
> You would need to write:
> 
>             mov.b    #LAMP_MAX_POWER,LAMP_power_memory_location
> 
> 
> 
>>Another think not clear, with following command
>>CMP.B   Mem_loc1,Mem_loc2
>>I compare the memory location address or the content, I think
>>the content.
> 
> 
> Yes.  My understanding so far is if you're using simple equates to define
> labels it ends up being generally:  # says the label is a literal (just a
> number).  You place it in front of a symbol which represents a number but
> and also in front of a number.  Without it is assumed to be an address
> reference.  Except in the case of Call where you would need it when
> referring to section and sub labels.  & for fixed addresses like
peripheral
> registers.  Leave it off when letting the assembler decide what the actual
> address is (tables, etc).
> 
> A comparison of the two modes you mentioned might be:
> 
> PowerUp	cmp.b    #LAMP_MAX_POWER,last_power_level
> 		jlo	   Restore
> 		jne      Default
> Restore     mov.b    last_power_level,Rpass1
> 		jmp      DonePU
> Default	mov.b    DefaultBrightness,Rpass1
> DonePU      call     #SetLevel
>             .......
> 
> Brighten    cmp.b    #LAMP_MAX_POWER,current_power_level
>             jeq      Done
> 		mov.b    current_power_level,last_power_level
> 		incr.b   current_power_level
> 		mov.b    current_power_level,Rass1
>             call     #SetLevel
> Done       	.......
>             ret
> 
> etc.
> 
> 
> 
>>I read apps note SLAU49C but I still have these doubt in mind
>>(may be I'm stipud).
> 
> 
> No, unless we both are ;)  I find the TI documentation very confusing.
> I've still got a lot to learn and it's slow going.  I spend an awful lot of
> time reading the addressing modes description and the instruction set
> summary, over and over again, while programming.  It's a lot easier to just
> program in C, but I'm stubborn and I need to really understand this.
> 
> Beyond studying example programs, another way I get some clues about syntax
> is to study the assembly output of the compiler (even if you want to
> program in assembly you could write code fragments in C periodically to see
> exactly how the syntax is applied to a generate a particular outcome).
> 
> I'm waiting for an in-depth primer on the instruction set, especially
> addressing modes, with complete explanations of where, why and how each is
> used, and where they are used differently with different instructions, and
> why, and many well-explained examples.
> 
> --Bruce
> 
> 
> 
> 
> .
> 
>  
> 
> ">http://docs.yahoo.com/info/terms/ 
> 
> 
> 


Thanks Al!

I still don't get two things:

1. In you last comment about CALLing a label without '#', do you mean that
DO_THIS is then understood to be a label for a number which is an address
to a memory location which in turn contains the address of the subroutine?

And also:

2. Why do we need to write

    jmp    DoThis

but

    call   #DoThis


to refer to the exact same address label?


--Bruce


> Think of it as C. # means "The immediate
number" or "the address of". In
> fact when used by the CALL instruction:-
>
> 	CALL	#DO_THIS
> 	...
> 	...
> DO_THIS:
> 	MOV	R4,R5
> 	RET
>
> It means the literal value of DO_THIS, which is the address of the
> label. If written:-
>
> 	CALL	DO_THIS
>
> It means call the address contained at the label DO_THIS. No different
> to C pointers really,
>
> aL



On Mon, Sep 15, 2003 at 11:39:10AM -0700, Bruce Cannon wrote:
> 1. In you last comment about CALLing a label
without '#', do you mean that
> DO_THIS is then understood to be a label for a number which is an address

Basically this means you are wanting an indirect call via the referenced
variable as opposed to calling the function at the specified address.

> 2. Why do we need to write
>     jmp    DoThis
> but
>     call   #DoThis

A good question - it's an inconsistency in the syntax - if I had designed it,
I would have made call the same as jmp, and used something like

	call	@fptr

for indirect function calls.

-- 
Clyde Stubbs                     |            HI-TECH Software
Email: clyde@clyd...          |          Phone            Fax
WWW:   http://www.htsoft.com/    | USA: (408) 490 2885  (408) 490 2885
PGP:   finger clyde@clyd...   | AUS: +61 7 3552 7777 +61 7 3552 7778
---
HI-TECH C: compiling the real world.

At 09:27 AM 9/16/2003 +1000, Clyde Stubbs wrote:
>On Mon, Sep 15, 2003 at 11:39:10AM -0700, Bruce
Cannon wrote:
> > 1. In you last comment about CALLing a label without '#', do you mean
that
> > DO_THIS is then understood to be a label for a number which is an
address
>
>Basically this means you are wanting an indirect call via the referenced
>variable as opposed to calling the function at the specified address.
>
> > 2. Why do we need to write
> >     jmp    DoThis
> > but
> >     call   #DoThis
>
>A good question - it's an inconsistency in the syntax - if I had designed
it,
>I would have made call the same as jmp, and used something like
>
>         call    @fptr
>
>for indirect function calls.
>...

IMHO, I think it's a mistake. This means you cannot have PC relative calls. 
Oh well, at least we are not fighting w/ the . (DOT) problem w/ BLISS!!!


// richard <http://www.imagecraft.com> 
<http://www.dragonsgate.net/mailman/listinfo> 


On Mon, 15 Sep 2003 16:49:43 -0700, Richard wrote:

><snip>
>Oh well, at least we are not fighting w/ the . (DOT) problem w/ BLISS!!!

Diss on BLISS?  The language in which much of VMS was written!
My friend and buddy language?  Why, I never!

Jon