75.2. AMD64

Zvláštnosti architektury amd64 (x86-64)

Odkazy:

Small code model
Code from 0x0 to 0x7effffff. Fastest code model.
Kernel code model
Code from 0xffffffff80000000 to 0xffffffffff000000.
Medium code model
Stejný jako Small code model. Možnost navíc large data sections. (.ldata, .lrodata, .lbss). Překladač musí používat instrukce movabs pro přístup large statickým datům a pro nahrávání adres do registruů.
Large code model
small position independent code model (PIC)
Medium position independent code model (PIC)
Large position independent code model (PIC)

Příklad 75.1. Použití 64-bit systémových volání

# File: example/as/amd64/hello64.s

	.section .data
msg:	.ascii	"Hello, world!\n"
len:	.long	. - msg

	.section .text
	.global _start
_start:	# Program starting point.  Linker looks for _start symbol.

	pushq $14; pop %rdx	# %rdx=14
	pushq $msg; pop %rsi	# %rsi=msg
	pushq $1;  pop %rdi	# %rdi=1 (STDOUT)
	pushq $1;  pop %rax	# write(rdi,rsi,rdx) 
	syscall

	pushq	$2;	pop	%rdi	# retval=1
	pushq	$0x3c;	pop	%rax	# exit()
	syscall

Příklad 75.2. Použití 32-bit systémových volání

# File: examples/as/amd64/hello.s
	# Použitá volání
	.equ	SYS_exit, 1
	.equ	SYS_write, 4

	# Standardní proudy
	.equ	STDIN,	0
	.equ	STDOUT,	1
	.equ	STDERR,	2

	.section .data
msg:	.ascii	"Hello, world!\n"
len:	.long	. - msg

	.section .text
	.global _start
_start:	# Program starting point.  Linker looks for _start symbol.

	movl	$SYS_write, %eax # sys_write(ebx=fd, ecx=ptr, edx=len)
	movl	$STDOUT, %ebx	# stdout
	leal	msg, %ecx	# Message start point
	movl	len, %edx	# Message lenght
	int	$0x80		# call kernel

	movl	$SYS_exit, %eax	# sys_exit()
	movl	$1, %ebx	# return value (only 8 bits)
	int	$0x80		# call kernel