我已经在一个小型操作系统上工作了一段时间,我已经得到了我需要的所有汇编代码。我可以轻松地在屏幕上绘制矩形和东西,但现在我希望能够更容易地使用它。我一直在做很多研究,但我找不到任何帮助。为了让您对我正在做的事情有一个大概的了解,这里是我想要的一段代码/代码
C代码
extern int drawRect(int x, int y, int width, int height);
int loop(void) {
drawRect(10, 10, 30, 30);
}
汇编代码
global drawRect
extern loop
drawRect:
; Rectangle code here
ret
; Main OS loop
os_loop:
; My other code here
call loop
jmp os_loop ; Go back and loop again.
; ect..
但是当我编译并运行它时,我看不到我的矩形。如果它对你有帮助,我正在使用MikeOS内核,并且为了编译,我只是将编译代码修改为此
#!/bin/sh
# This script assembles the MikeOS bootloader, kernel and programs
# with NASM, and then creates floppy and CD images (on Mac OS X)
# Only the root user can mount the floppy disk image as a virtual
# drive (loopback mounting), in order to copy across the files
echo ">>> BlueOS OS X build script - requires nasm and mkisofs"
echo ">>> Assembling bootloader..."
cd MyDirectory
nasm -O0 -f bin bootload/bootload.asm -o bootload/bootload.bin || exit
echo ">>> Assembling BlueOS kernel and other files..."
cp disk_images/mikeos.flp disk_images/mikeos.dmg
nasm -O0 -f elf kernel.asm -o kernel.bin || exit
cd other
for i in *.asm
do
nasm -O0 -f elf $i -o `basename $i .asm`.bin || exit
done
echo ">>> Assembling C code..."
for i in *.c
do
gcc -ffreestanding -c $i -o `basename $i .c`.o || exit
done
cd ..
echo ">>> Creating floppy..."
cp disk_images/mikeos.flp disk_images/mikeos.dmg
echo ">>> Adding bootloader to floppy image..."
dd conv=notrunc if=bootload/bootload.bin of=disk_images/mikeos.dmg || exit
echo ">>> Copying BlueOS kernel and programs..."
dev=`hdid -nobrowse -nomount disk_images/mikeos.dmg`
mkdir tmp-loop && mount -t msdos ${dev} tmp-loop && cp kernel.bin tmp-loop/
echo ">>> Unmounting loopback floppy..."
diskutil unmount tmp-loop || exit
hdiutil detach ${dev}
rm -rf tmp-loop
echo ">>> BlueOS floppy image is disk_images/mikeos.dmg"
echo ">>> Creating CD-ROM ISO image..."
rm -f disk_images/mikeos.iso
mkisofs -quiet -V 'MIKEOS' -input-charset iso8859-1 -o disk_images/mikeos.iso -b mikeos.dmg disk_images/ || exit
echo '>>> Done!'
侧面说明: 我在Mac OS X上,如果这对任何事都有所帮助。 侧面问题: 是否可以使用C ++代替C?我是OOP的粉丝。
答案 0 :(得分:2)
混合C和汇编取决于编译器如何配置来处理参数。如果你正在使用gcc,它还取决于你是否正在构建16/32/64位。 C ++也是如此。有关详情,请参阅http://en.wikipedia.org/wiki/X86_calling_conventions。