Skip to content

Instantly share code, notes, and snippets.

@alexgpg
Created February 21, 2012 21:20
Show Gist options
  • Save alexgpg/1879025 to your computer and use it in GitHub Desktop.
Save alexgpg/1879025 to your computer and use it in GitHub Desktop.
GNU Assembler Hello World 64 bit edition
/* GNU Assembler Hello World 64 bit edition */
/* Compile: gcc -nostdlib hello_world_64_without_main.s -o hello_world_64_without_main.bin
* Run: ./hello_world_64_without_main.bin
*/
/*
* Начало сегмента данных
*/
.data
/*
* Строка, которую будем печатать. Точнее метка указывающая
* на ее начало.
*/
hello_str:
/*
* А это сами данные строки.
*/
.string "Hello, 64-bit world!\n"
/*
* Вычисление длины строки и помещение ее(длины) в символ
* hello_str_length. -1 нужен, чтобы не выводить нулевой
* символ, который вставляет .string
*/
.set hello_str_length, . - hello_str - 1
/*
* Начало сегмента кода.
*/
.text
/*
* Объявляем _start глобавльным символом.
*/
.globl _start
.type _start, @function /* _start - функция (а не данные) */
_start:
movq $1, %rax /* поместить номер системного вызова
write = 1 в регистр %rax */
movq $1, %rdi /* первый параметр - в регистр %ebx;
номер файлового дескриптора
stdout - 1 */
movq $hello_str, %rsi /* второй параметр - в регистр %rsi;
указатель на строку */
movq $hello_str_length, %rdx /* третий параметр - в регистр
%rdx; длина строки */
syscall /* системный вызов */
movq $60, %rax /* номер системного вызова exit - 60 */
movq $0, %rdi /* передать 0 как значение параметра */
syscall /* вызвать exit(0) */
/*---------------------------end---------------------------------------------*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment