我正在尝试使用内联汇编...我读过这个页面http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx但我无法理解传递给我的函数的参数.
我正在写一个C写的例子..这是我的函数头:
write2(char *str, int len){
}
Run Code Online (Sandbox Code Playgroud)
这是我的汇编代码:
global write2
write2:
push ebp
mov ebp, esp
mov eax, 4 ;sys_write
mov ebx, 1 ;stdout
mov ecx, [ebp+8] ;string pointer
mov edx, [ebp+12] ;string size
int 0x80 ;syscall
leave
ret
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能将代码传递给C函数...我正在做这样的事情:
write2(char *str, int len){
asm ( "movl 4, %%eax;"
"movl 1, %%ebx;"
"mov %1, %%ecx;"
//"mov %2, %%edx;"
"int 0x80;"
:
: "a" (str), "b" (len)
);
}
Run Code Online (Sandbox Code Playgroud)
那是因为我没有输出变量,所以我该如何处理呢?此外,使用此代码:
global main
main:
mov ebx, 5866 ;PID
mov ecx, …Run Code Online (Sandbox Code Playgroud) 我正在使用XNA 3.1开发3D Spaceship游戏
我试图将我的绘画代码与游戏逻辑分开(altought XNA几乎就是这样).
我正在使用一个特殊的静态类,在屏幕上绘制我的模型......主要的Game类在绘画中使用此代码:
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.Black);
// Draws the stage (the skybox and objects like rocks)
stageManager.Draw(gameTime, GraphicsDevice, camera);
// Draws each player and each Enemy on stage given the camera
foreach (Player p in players)
p.Draw(camera);
foreach(Enemy e in enemies)
e.Draw(camera);
if(Configuration.Debug)
col.renderColBoundings(GraphicsDevice, camera);
GraphicHelper.drawOverlayText("50", "10"); // "Error" line...
base.Draw(gameTime);
}
Run Code Online (Sandbox Code Playgroud)
但是当我画出文字时,会出现一些奇怪的东西......这是一张图片(原创):

正如你所看到的,一切看起来都是重叠的(但在适当的位置)......就像飞船涡轮机一样.
里面的代码GraphicHelper.drawOverlayText是这样的:
public static void drawOverlayText(String p1Hp, String currEnemies)
{
string text1 = "Player1: " + …Run Code Online (Sandbox Code Playgroud) 我想写一个小的Linux内核模块,它可以显示所有正在运行的进程的PID.我有以下代码:
/*
* procInfo.c My Kernel Module for process info
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
/*
* The init function, called when the module is loaded.
* Returns zero if successfully loaded, nonzero otherwise.
*/
static int mod_init(void)
{
printk(KERN_ALERT "ProcInfo sucessfully loaded.\n");
return 0;
}
/*
* The exit function, called when the module is removed.
*/
static void mod_exit(void)
{
printk(KERN_ALERT "ProcInfo sucessfully unloaded.\n");
}
void getProcInfo()
{
printk(KERN_INFO "The process is \"%s\" (pid %i)\n",
current->comm, …Run Code Online (Sandbox Code Playgroud)