From d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:55:07 +0200 Subject: Add new code Signed-off-by: Carlos Maiolino --- PGU/CHAP8/printcall.s | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 PGU/CHAP8/printcall.s (limited to 'PGU/CHAP8/printcall.s') 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 + -- cgit v1.2.3