Chinaunix首页 | 论坛 | 博客
  • 博客访问: 106283
  • 博文数量: 76
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 400
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-18 21:41
文章分类

全部博文(76)

文章存档

2011年(76)

我的朋友

分类:

2011-08-24 17:48:08

  • Assembly file extensions can be either .s or .asm
     
  • To include another file in your assembly file:
    .include "Defines.h"        ; include "Defines.h" file for use in assembly file
     
  • To label your code so CodeWarrior can debug it:
  1. First, for CodeWarrior to be able to access your function you need the following line:

    .function "MyFile", PPC_Start_Asm, PPC_End_Asm - PPC_Start_Asm

    Where "MyFile" is the name of your file (without the extension), PPC_Start_Asm is a label at the beginning of your code, and PPC_End_Asm is a label at the end of your code.  The "PPC_End_Asm - PPC_Start_Asm" portion tells CodeWarrior the size of your function in bytes (difference between end and beginning addresses).
  1. Next, tell the compiler that the following section is your assembly code and not something else. Put .text at the start of your assembly function:

    .text
     
  2. Finally, put a label for the beginning of your program, following the label for PPC_Start_Asm:

    PPC_Start_Asm:
    MyFunction:

    Both PPC_Start_Asm and MyFunction will contain the same address.
     

Here is a complete example of a simple program:

.include "defines.h"

.function "MyFile", PPC_Start_Asm, PPC_End_Asm - PPC_Start_Asm

.text

PPC_Start_Asm:

MyFunction:

    ; To Do: place your assembly code here

PPC_End_Asm:

  • To include other Assembly files for use and debugging:
    Do Not use .include to include other assembly files that you want toe use and debug, because then you will not be able to run through the file with the step-by-step debugger.  The actual program may work but you can not go through the included code line by line. You can include subroutines or any other label (i.e. variables) from one assembly file to be used in another file.  Do remember though to add the .function and .text and other required assembly definitions.

    Place the .import in the assembly file (at the top) from which you want to call the subroutine. Basically can look at it like placing the prototype of the function at the top of the assembly file.

    .import My_Function

    Then place the .export in the assembly file (at the top) that actually contains the subroutine that you want to call.

    .export My_Function

    Example:

    In “MainSource.asm”

.import My_Function

; your other code

; call to My_Function subroutine

        bl     My_Function

; more code

In “Other_File.asm”

.export My_Function

My_Function:

        ;your My_Function code

        blr             ; return to MainSource file
 

阅读(528) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~