Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22077

Compile an asm bootloader with external c code

$
0
0

I write a boot loader in asm and want to add some compiled C code in my project.

I created a test function here:

test.c

__asm__(".code16\n");void print_str() {    __asm__ __volatile__("mov $'A' , %al\n");    __asm__ __volatile__("mov $0x0e, %ah\n");    __asm__ __volatile__("int $0x10\n");}

And here is the asm code (the boot loader):

hw.asm

[org 0x7C00][BITS 16][extern print_str] ;nasm tipstart:mov ax, 0mov ds, axmov es, axmov ss, axmov sp, 0x7C00mov si, namecall print_stringmov al, ''int 10hmov si, versioncall print_stringmov si, line_returncall print_stringcall print_str ;call functionmov si, welcomecall print_stringjmp mainloopmainloop:mov si, promptcall print_stringmov di, buffercall get_strmov si, buffercmp byte [si], 0je mainloopmov si, buffer;call print_stringmov di, cmd_versioncall strcmpjc .versionjmp mainloop.version:mov si, namecall print_stringmov al, ''int 10hmov si, versioncall print_stringmov si, line_returncall print_stringjmp mainloopname db 'MOS', 0version db 'v0.1', 0welcome db 'Developped by Marius Van Nieuwenhuyse', 0x0D, 0x0A, 0prompt db '>', 0line_return db 0x0D, 0x0A, 0buffer times 64 db 0cmd_version db 'version', 0%include "functions/print.asm"%include "functions/getstr.asm"%include "functions/strcmp.asm"times 510 - ($-$$) db 0dw 0xaa55

I need to call the c function like a simple asm functionWithout the extern and the call print_str, the asm script boot in VMWare.

I tried to compile with:

nasm -f elf32 

But i can't call org 0x7C00


Viewing all articles
Browse latest Browse all 22077

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>