我正在尝试在Turbo C++ 3.0中实现fopen
,我需要用asm inline编写它。
我写了一段代码,但是(毫不意外……)它没有起作用(编译失败)。
代码如下:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>
int my_fopen_w(char fname[])
{
int fd;
char status;
status = 'w'; // I need to write to a file and delete previous content
asm{
mov bl, status
xor bh,bh
push bp
mov bp, sp
push bx
push fname
//Same as fopen now fopen(file path= fname, "w" = bx)
call _fopen
add sp,8
// Returned value in AX register
mov fd, ax // That line may be incorrect, my teacher demands an Integer returned value
}
return fd;
}
我遇到了一个错误:Turbo C无法识别_fopen
调用。
Haim
_fopen
为全局对象(即在汇编代码开头添加.global _fopen
)。 - Ctx