LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2018, 04:05 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
syscall vs int 0x80.


The following is the classical Hello world program. When I run it nothing happens. Here it is:
Code:
# ----------------------------------------------------------------------------------------
# Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
# To assemble and run:
#
#     gcc -c hello.s && ld hello.o && ./a.out
#
# or
#
#     gcc -nostdlib hello.s && ./a.out
# ----------------------------------------------------------------------------------------
.intel_syntax noprefix
        .global _start

        .text
_start:
        # write(1, message, 13)
        mov     ax,4                # system call 1 is write
        mov     bx,1                # file handle 1 is stdout
        mov     cx,message           # address of string to output
        mov     dx,13               # number of bytes
        int     0x80                         # invoke operating system to do the write

        # exit(0)
        mov     ax,1               # system call 60 is exit
        xor     bx,bx              # we want return code 0
        int     0x80                   # invoke operating system to exit
message:
        .ascii  "Hello, world\n"

#  $ gcc -c hello.s && ld hello.o && ./a.out
#  Hello, World
If instead of int 0x80 I use syscall then the register usage is different but, more important, I get 'Illegal instruction' at runtime. What should I use to make a system call: int 0x80 or syscall? My intel processor is Intel Celeron N3050 which is 64-bit.

Last edited by stf92; 06-02-2018 at 04:26 PM.
 
Old 06-03-2018, 03:46 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
As a start, choose a platform:
for 32-bit (x86, gcc option -m32), use 32-bit registers like EAX and EBX, and instuction INT 0x80
for 64-bit (amd64, gcc option -m64), use 64-bit registers like RAX and RBX, and instruction SYSCALL

https://en.wikibooks.org/wiki/X86_As...ing_with_Linux
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between mmap2 syscall and mmap_pgoff syscall for 32-bit Linux Michael Schwarzer Linux - General 1 02-03-2018 05:31 PM
Linux assembler tutorial - int 0x80 vs syscall zOSGuy Programming 1 05-10-2016 11:38 AM
[SOLVED] specifying output int based on input int and source IP on multiple 802.1q, tacorama Linux - Networking 1 05-05-2011 07:30 AM
[SOLVED] Assembly language printing integers to the stdout using int 0x80 yaami Programming 9 07-08-2010 10:43 PM
hooking interrupts (int 0x80 and sysenter) hamedn Programming 5 09-30-2009 12:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration