我已经在一个小型操作系统上工作了一段时间,并且我已经获得了我需要的所有汇编代码。我可以轻松地在屏幕上绘制矩形和东西,但现在我希望能够更轻松地使用它。我一直在做很多研究,但我发现没有任何帮助。为了让您大致了解我在做什么,这是我想要的一段代码/代码
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 的粉丝。