For the moment I'm experementing with compiling things into com files.
I've succeded compiling this into a com file:
Code: Select all
start.asm:
[BITS 32]
[global start]
[extern _main]
start:
call _main
ret
main.c
void main(void)
{
__asm__ (
"mov $'e', %%al\n\t"
"mov $0x0E, %%ah\n\t"
"xor %%bl, %%bl\n\t"
"int $0x10\n\t"
:
:
);
}
Code: Select all
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100 :
{
code = .; _code = .; __code = .;
*(.text)
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
}
end = .; _end = .; __end = .;
}
Code: Select all
still same start.asm
main.c:
void putch(char c)
{
__asm__ (
"mov %0, %%al\n\t"
"mov $0x0E, %%ah\n\t"
"xor %%bl, %%bl\n\t"
"int $0x10\n\t"
:
: "r" (c)
);
}
void main(void)
{
putch('H');
}
Code: Select all
[bits 32]
[org 0x100]
start: call _main
ret
; void putch(char c)
_putch: push ebp
mov ebp, esp
; Print a character
mov al, [ebp+0x8]
mov al, al
mov ah, 0x0E
xor bl, bl
int 0x10
pop ebp
ret
; void main(void)
_main: push ebp
; putch('H');
; Print a character
mov al, 0x48 ; H
mov ebp, esp
mov ah, 0x0E
xor bl, bl
int 0x10
pop ebp
ret
(sorry for the long message )
edit:
I noticed if I remove the
Code: Select all
pop ebp