问题描述
我正在尝试以纯汇编语言编写引导加载程序时,在gcc gnu汇编程序中构建16位内核,但是在单字符可以的情况下我无法打印出字符串:
i am trying to build a 16bit kernel in gcc gnu assembly while my bootloader is written in pure assembly but i have trouble printing out strings while single character are okay:
这是我的bootloader.asm:
Here is my bootloader.asm:
org 0x7c00
bits 16
section .text
mov ax,0x1000
mov ss,ax
mov sp,0x000
mov esp,0xfffe
xor ax,ax
mov es,ax
mov ds,ax
mov [bootdrive],dl
mov bh,0
mov bp,zeichen
mov ah,13h
mov bl,06h
mov al,1
mov cx,6
mov dh,010h
mov dl,01h
int 10h
load:
mov dl,[bootdrive]
xor ah,ah
int 13h
jc load
load2:
mov ax,0x1000
mov es,ax
xor bx,bx
mov ah,2
mov al,1
mov cx,2
xor dh,dh
mov dl,[bootdrive]
int 13h
jc load2
mov ax,0
mov es,ax
mov bh,0
mov bp,zeichen3
mov ah,13h
mov bl,06h
mov al,1
mov cx,13
mov dh,010h
mov dl,01h
int 10h
mov ax,0x1000
mov es,ax
mov ds,ax
jmp 0x1000:0x000
zeichen db 'hello2'
zeichen3 db 'soweit so gut'
bootdrive db 0
times 510 - ($-$$) hlt
dw 0xaa55
这里是我的kernel.c:
and here my kernel.c:
asm("jmp main");
void print()
{
for(int i=0;i<5;i++)
{
asm("mov $0x0e,%ah");
asm("mov $0x00,%bh");
asm("mov %0,%%al":: "" ('g'));
asm("int $0x10");
}
}
void main()
{
asm("mov $0x1000,%eax;"
"mov %eax,%es;"
"mov %eax,%ds");
const char string[]="hall0";
print();
for(int i=0;i<5;i++)
{
asm("mov $0x0e,%ah");
asm("mov $0x00,%bh");
asm("mov %0,%%al":: "" (string[i]));
asm("int $0x10");
}
asm(".rept 512;"
" hlt ;"
".endr");
}
我使用的命令是:nasm -f bin -o bootloader.bin bootloader.asm
和gcc kernel.c -c -o kernel.o -m16 -nostdlib -ffreestanding&&ld -melf_i386 kernel.o -o kernel.elf&&objcopy -O binary kernel.elf kernel.o&&cat bootloader.bin kernel.elf>myOS.bin&&qemu-system-i386 myOS.bin
在我的Linux Mint Cinnamon版本18上.它在"soweit so gut"之后打印出10 g,这是它应该打印的5 g,再加上"hall0"中的字符数,但是我不打印"hall0".因此,在使用gcc gnu汇编程序时,我一定在bootloader.asm中做错了什么,也许设置了错误的栈或其他什么东西.也许有人可以帮我该怎么办?
the commands i use are:nasm -f bin -o bootloader.bin bootloader.asm
andgcc kernel.c -c -o kernel.o -m16 -nostdlib -ffreestanding&&ld -melf_i386 kernel.o -o kernel.elf&&objcopy -O binary kernel.elf kernel.o&&cat bootloader.bin kernel.elf>myOS.bin&&qemu-system-i386 myOS.bin
on my Linux Mint Cinnamon version 18.It prints out 10 g's after "soweit so gut" these are the 5 g's it should print plus the number of characters from "hall0" but i doesnt print "hall0". So i must have done something wrong in the bootloader.asm for the use of the gcc gnu assembler, maybe set up the stack wrong or something. Maybe someone can help me what to do?
推荐答案
您必须将'kernel.asm'编译为bin文件,然后执行cat命令
You have to compile the 'kernel.asm' to a bin file and then do the cat command
这篇关于实模式下的gcc gnu程序集内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!