summaryrefslogtreecommitdiff
path: root/PGU/CHAP8/printcall.s
diff options
context:
space:
mode:
Diffstat (limited to 'PGU/CHAP8/printcall.s')
-rw-r--r--PGU/CHAP8/printcall.s34
1 files changed, 34 insertions, 0 deletions
diff --git a/PGU/CHAP8/printcall.s b/PGU/CHAP8/printcall.s
new file mode 100644
index 0000000..2d50e73
--- /dev/null
+++ b/PGU/CHAP8/printcall.s
@@ -0,0 +1,34 @@
+# Just an example of calling printf() using ASM
+
+.section .data
+ firststring:
+ .ascii "Hello! %s is a %s who lives the number %d\n\0"
+ name:
+ .ascii "Maiolino\0"
+ personstring:
+ .ascii "person\0"
+
+ numberloved:
+ .long 123
+
+.section .text
+.globl _start
+
+ # Recall we are using x86_64 ABI here, so we pass arguments through
+ # registers instead of on the stack.
+
+_start:
+ movq $firststring, %rdi
+ movq $name, %rsi
+ movq $personstring, %rdx
+
+ # We don't use $numberloved here because $ sign means 'immediate'
+ # addressing. Here we want the 'CONTENT' pointed by label 'numberloved'
+ # so, we use 'direct' addressing, by ommiting the $ sign, so we get the
+ # information "pointed by" the label numberloved itself.
+ movq numberloved, %rcx
+ call printf
+
+ movq $0, %rdi
+ call exit
+