我正在从头开始构建一个简单的操作系统,所以我正在测试一些启动扇区代码,我正在使用Qemu进行模拟.
我的启动扇区代码应该在操作系统启动时打印"A".
这是引导扇区代码的第一个版本(没有使用函数调用)
[org 0x7c00]
mov al,'A'
mov ah,0x0e ; int 10/ ah = 0eh -> scrolling teletype BIOS routine
int 0x10
jmp $
times 510 -( $ - $$ ) db 0
dw 0xaa55
Run Code Online (Sandbox Code Playgroud)
执行nasm生成的二进制文件后使用:
qemu-system-i386 test.bin
Run Code Online (Sandbox Code Playgroud)
结果是正确的,字符'A'出现在它应该的位置
但是,在尝试使用打印存储在al中的字符的功能后,屏幕上不会打印任何内容
这是test.asm文件的第二个版本(这次包括函数调用)
[org 0x7c00]
mov al,'A'
call my_print_function
jmp $
times 510 -( $ - $$ ) db 0
dw 0xaa55
my_print_function:
pusha ; push all registers
; same code as the first version to print a character stored in al …Run Code Online (Sandbox Code Playgroud) 我有这个简单的C源代码:
#include <stdio.h>
extern int Sum(int,int);
int main()
{
int a,b,s;
a=1 , b=2;
s = Sum(a,b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我有这个s.asm定义函数_Sum:
global _Sum
_Sum:
push ebp ; create stack frame
mov ebp, esp
mov eax, [ebp+8] ; grab the first argument
mov ecx, [ebp+12] ; grab the second argument
add eax, ecx ; sum the arguments
pop ebp ; restore the base pointer
ret
Run Code Online (Sandbox Code Playgroud)
现在,我编译.asm使用:
nasm s.asm -f elf -o s.o
Run Code Online (Sandbox Code Playgroud)
并使用以下方法编译和链接.c文件:
gcc s.o test.o -o testapp
Run Code Online (Sandbox Code Playgroud)
这是结果:
/tmp/ccpwYHDQ.o: In …Run Code Online (Sandbox Code Playgroud) 我有一个父进程和一个子进程(使用fork创建子进程)一些在父进程中定义此代码的位置:
FILE* pfile = fopen("log.txt","w");
while (1) {
serve child requests
fprintf (pfile,"some data\n");
}
fclose (pfile);
Run Code Online (Sandbox Code Playgroud)
问题是代码的最后一行永远不会被执行,因为无限循环不会终止(这是程序应该如何操作)..所以文件永远不会被关闭,连续写入的数据不会被保存到文件中.
我怎么解决这个问题 ?
任何帮助将不胜感激,谢谢
我试图解决这个简单的问题http://codeforces.com/problemset/problem/158/B ,我想出了解决它的代码:
int main() {
int n,x,sum;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x; sum += x;
}
for (int j = 1; j <= sum; j++) {
double q = (sum*1.0) / j;
if (q <= 4*1.0) {
cout << j;
break;
}
}
return 0;
Run Code Online (Sandbox Code Playgroud)
无论这个解决方案的正确性如何,我注意到没有任何东西被打印但是如果我改变了这条线
cout << j;
Run Code Online (Sandbox Code Playgroud)
对此:
cout << ' ' << j;
Run Code Online (Sandbox Code Playgroud)
它打印答案(当然在空格之后).
我在ideone.com上测试了我的代码(这是我的解决方案的实际链接http://ideone.com/wldwvy),行为如上所述,但是当我在这个网站上测试它时,http://www.compileonline .com/compile_cpp0x_online.php输出很好(不必包含空格).
完全尴尬的是当我试图在一个非常小的测试用例上提交我的解决方案时,它给了我(超出时间限制判决)的代码.
为什么会这样?