using syscall and bios interrupt's in asm

Salamo Alikom
i am trying to learn asm ,so i create tow simple program ,the first use syscall and secont use interrupt's :
syscall :
Code:
segment .data
 ftest db 'Learn ASM',0
 nbytes equ $-ftest
segment .text
 global _start
 _start:
 mov eax,4 ;write number syscall
 mov ebx,1 ;file descriptor ,output to screen
 mov ecx,ftest ;pointer to text
 mov edx,nbytes ;number of bytes
 int 0x80 ;call kernel
 mov eax,1 ;exit syscall
 mov ebx,0 
 int 80h ;call kernel
Code:
nasm -f elf -o write.o write.asm
ld -s -o write write.o
./write
output is empty here .
interrupt :
Code:
segment .data
 ftest db 'Learn ASM',0
 nbytes equ $-ftest
segment .text
 global _start
 _start:
 mov ah,09 ;bios video service
 mov dx,ftest ;ptr to text
 int 21h ;call bios service
 mov eax,1 ;exit syscall
 mov ebx,0
 int 80h ;call kernel

Code:
nasm -f elf -o write.o write.asm
ld -s -o write write.o
here i get this msg :
Code:
write.o(.text+0x1a): In function `_start':
: relocation truncated to fit: R_386_16 .data
 
FreeBSD doesn't expect parameters to be passed in registers. It expects them in the stack. You're using the Linux calling convention which needs... you've guessed it, the Linux compat layer, to work. Try this instead:
Code:
push nbytes
push ftest
push 1
push 0
mov eax,4
int 0x80
push 0
mov eax,1
int 0x80

BTW, ftest doesn't need to be zero-terminated as int 0x80 function 4 uses the string length you pass to it and doesn't calculate it itself.
On the other hand, it might use an (aesthetic) "0xa".

As for your second code, you're not using BIOS interrupts. You're using MS-DOS interrupts. No wonder it's not working.
But even if you used genuine BIOS interrupts, it shouldn't work on anything like a modern operating system running under protected mode (e.g. FreeBSD), unless you introduce some black magic in there.
 
Check out the FreeBSD/i386 and FreeBSD/amd64 ABI (i.e. calling conventions of the kernel). They aren't the same as under Linux.

Here's a FreeBSD assembler tutorial that covers hello world for both platforms and uses GNU as(1) that you may find useful.
 
Back
Top