initial import
[staff/goc4/2018bti7061.git] / asm-8-strings / examples / clib / eatclib3.asm
1 ; Source name : EATCLIB.ASM
2 ; Executable name : EATCLIB
3 ; Version : 2.0
4 ; Created date : 2/11/2014
5 ; Last update : 2/11/2014
6 ; Author : Emmanuel Benoist
7 ; Description : Demonstrates calls made into clib, using NASM 2.05
8 ; to send a short text string to stdout with puts().
9 ;
10 ; Build using these commands:
11 ; nasm -f elf64 -g -F stabs eatclib3.asm
12 ; gcc eatclib3.o -o eatclib3
13
14 [SECTION .data] ; Section containing initialised data
15
16 MathMsg: db "%d +%d =%d ",10, 0 ; We do not need the length because of c library
17
18 [SECTION .bss] ; Section containing uninitialized data
19
20 [SECTION .text] ; Section containing code
21
22 extern printf ; Simple "put string" routine from clib
23 global main ; Required so linker can find entry point
24
25 main:
26 push rbp ; Set up stack frame for debugger
27 mov rbp,rsp
28 push rbx ; Must preserve ebp, ebx, esi, & edi
29 push rsi
30 push rdi
31 ;;; Everything before this is boilerplate; use it for all ordinary apps!
32 mov rdi, MathMsg ; Write address of message in RDI
33 mov rsi, 10
34 mov rdx, 20
35 mov rcx, 30
36 xor rax,rax
37 call printf ; Call clib function for displaying strings
38
39 ;;; Everything after this is boilerplate; use it for all ordinary apps!
40 pop rdi ; Restore saved registers
41 pop rsi
42 pop rbx
43 mov rsp,rbp ; Destroy stack frame before returning
44 pop rbp
45 ret ; Return control to Linux