[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

Chapter 7.

 

PowerPC-Specific Information



The CodeWarrior PowerPC assembler supports all instructions for the PowerPC processor.

This chapter provides information specific to the PowerPC processor. For example, this chapter discusses features and examples that differ from the information provided in the other chapters of this manual.

This chapter includes the following topics:


Related Documentation

PowerPC Microprocessor Family: The Programming Environments for 32-Bit Microprocessors (published by Motorola, Inc.) is helpful for writing PowerPC assembly language code.


PowerPC-Specific Examples

This section contains examples shown in previous chapters that differ for the PowerPC assembler. Table 7.1 lists the PowerPC-specific examples and the corresponding examples shown in previous chapters.

Corresponding example table:

 

Original Example
PowerPC-Specific Example
Listing 2.2  
Listing 7.1  
Listing 4.2  
Listing 7.2  
Listing 4.3  
Listing 7.3  
Listing 4.4  
Listing 7.4  
Listing 4.6  
Listing 7.5  
Listing 4.8  
Listing 7.7  
Listing 4.12  
Listing 7.8  
Listing 4.14  
Listing 7.10  

Listing 7.1 shows the scope of local labels in macros.

PowerPC example: the scope of local labels in a macro:


MAKEPOS:  .MACRO
     cmpdi   r3, 1
     bne     @SKIP
     neg     r3,r3
@SKIP:  ;Scope of this label is within the macro
    .ENDM
START:
     lis     r2, COUNT@h    ; COUNT is defined elsewhere
     ori     r2,r2,COUNT@l
     cmpdi   r3, 1
     bne     @SKIP
     MAKEPOS
@SKIP:    ;Scope of this label is START to END
          ;excluding lines arising from
          ;macro expansion
      add    r2,r2,1
END:  


Listing 7.2 shows a macro that uses the .mexit directive.

PowerPC example: conditional macro using the .mexit directive:


; define a macro
addto		:		.macro   val,dest
				.if val==0
						nop 
				.mexit				 ; execution goes to the statement
								 ; immediately after the .endm directive
				.elseif val==1
						addi dest,dest,1
				.mexit				 ; execution goes to the statement
								 ; immediately after the .endm directive
				.endif
; if val is not equal to either 0 or 1,
; add dest and val
				addi dest,dest,val
; end macro definition
				.endm


Listing 7.3 shows assembly language code that calls the addto macro shown in Listing 7.2.

PowerPC example: assembly code that calls the addto macro:


; specify an executable code section
				.text
				xor   r3,r3,r2
; call the addto macro
				addto r3,0
				addto r3,1
				addto r3,2
				addto r3,3


Listing 7.4 shows the listing file for the macro calls shown in Listing 7.3.

PowerPC example: Listing file contents for addto macro calls:


.text
    nop
    addi    r3,r3,1
    addi    r3,r3,2
    addi    r3,r3,3


Listing 7.5 shows the setup macro, which moves an integer into a register and branches to the label _final_setup.

PowerPC example: the setup macro:


setup:       .macro name
             lis   r3, name@h
             ori   r3, name@l
             b    _final_setup
             .endm


Listing 7.6 shows one way to invoke the setup macro. (Listing 7.6 shows the same call as Listing 4.7.)

PowerPC example: calling setup:


               #define VECT 0              
               setup  VECT


Listing 7.7 shows how the assembler expands the setup macro after a particular call.

PowerPC example: expanded setup:


           lis    r3,VECT
           b      _final_setup


Listing 7.8 shows a macro that uses unique labels.

PowerPC example: unique label macro:


my_macro: .macro
          foo\@ = my_count
my_count  .set my_count + 1
          addi r3,r3,foo\@
          b    label\@
          add  r4,r4,r3
label\@:
          nop
          .endm


Listing 7.9 shows a call to the my_macro macro twice (with my_count initialized to 0). (Listing 7.9 shows the same calls as Listing 4.13.)

PowerPC example: invoking my_macro:


mycount  .set 0
         my_macro
         my_macro


Listing 7.10 shows the assembler output for the unique label macro.

PowerPC example: expanded my_macro calls:


foo??0000   =     my_count
my_count    .set  my_count + 1
            addi  r3,r3,foo??0000
            b     label??f0000
            add   r4,r4,r3
label??0000
            nop
foo??0001   =     my_count
my_count    .set  my_count + 1
            addi  r3,r3,foo??0001
            b     label??0001
            add   r4,r4,r3
label??0001
            nop


 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 20, 2000