【发布时间】:2018-08-23 08:49:16
【问题描述】:
我正在尝试在 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 呼叫。
海姆
【问题讨论】:
-
您需要以某种方式将
_fopen声明为全局对象(即在您的汇编代码开头的.global _fopen) -
你为什么要练习 MS DOS 的汇编程序编程?
-
@Haim 为什么你的学校教你成为 1990 年的程序员?你需要问他们为什么不教你一些实际上会给你工作的东西。
-
现在已经不是问题了,我求助,我练习组装的原因并不重要。
-
插入对 _fopen 的 c-call 并查看生成的 asm 代码。也许,还有另一个 _,你必须调用 __fopen?
标签: c file fopen inline-assembly turbo-c++