summaryrefslogtreecommitdiff
path: root/PGU/CHAP8/printcall.s
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-10 22:55:07 +0200
committerCarlos Maiolino <[email protected]>2025-07-10 22:56:55 +0200
commitd98f46ce647846b0aa30b2e16a30fd4e152a1bf5 (patch)
tree267474fcc77cf20b428f6f4c7f768ca09f4cfe0e /PGU/CHAP8/printcall.s
parent869e68986aa8f69af6e7842260a68d1e5c6f796f (diff)
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
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
+