Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3308368
  • 博文数量: 258
  • 博客积分: 9440
  • 博客等级: 少将
  • 技术积分: 6998
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-03 10:28
个人简介

-- linux爱好者,业余时间热衷于分析linux内核源码 -- 目前主要研究云计算和虚拟化相关的技术,主要包括libvirt/qemu,openstack,opennebula架构和源码分析。 -- 第五届云计算大会演讲嘉宾 微博:@Marshal-Liu

文章分类

全部博文(258)

文章存档

2016年(1)

2015年(4)

2014年(16)

2013年(22)

2012年(41)

2011年(59)

2010年(40)

2009年(75)

分类: LINUX

2009-09-04 13:56:19

  • 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
 

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

cmk1282010-04-11 11:22:09

一个专为操作系统开发者與及汇编高手而设的x86-ia32调试器 http://code.google.com/p/peter-bochs/