summaryrefslogtreecommitdiff
path: root/CSAPP/tmul_asm.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 /CSAPP/tmul_asm.s
parent869e68986aa8f69af6e7842260a68d1e5c6f796f (diff)
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'CSAPP/tmul_asm.s')
-rw-r--r--CSAPP/tmul_asm.s79
1 files changed, 79 insertions, 0 deletions
diff --git a/CSAPP/tmul_asm.s b/CSAPP/tmul_asm.s
new file mode 100644
index 0000000..288a36a
--- /dev/null
+++ b/CSAPP/tmul_asm.s
@@ -0,0 +1,79 @@
+ .file "tmul_asm.c"
+ .text
+ .globl tmul_bug
+ .type tmul_bug, @function
+tmul_bug:
+.LFB0:
+ .cfi_startproc
+ imulq %rdi, %rsi
+ movq %rsi, (%rdx)
+#APP
+# 5 "tmul_asm.c" 1
+ setae %al
+# 0 "" 2
+#NO_APP
+ movl $0, %eax
+ ret
+ .cfi_endproc
+.LFE0:
+ .size tmul_bug, .-tmul_bug
+ .globl tmul_ok
+ .type tmul_ok, @function
+tmul_ok:
+.LFB1:
+ .cfi_startproc
+ pushq %rbx
+ .cfi_def_cfa_offset 16
+ .cfi_offset 3, -16
+ imulq %rdi, %rsi
+ movq %rsi, (%rdx)
+#APP
+# 13 "tmul_asm.c" 1
+ setae %bl # Set low-order byte
+ movzbl %bl, %eax # Zero extend to be res
+# 0 "" 2
+#NO_APP
+ popq %rbx
+ .cfi_def_cfa_offset 8
+ ret
+ .cfi_endproc
+.LFE1:
+ .size tmul_ok, .-tmul_ok
+ .globl tmul_ok2
+ .type tmul_ok2, @function
+tmul_ok2:
+.LFB2:
+ .cfi_startproc
+ imulq %rdi, %rsi
+ movq %rsi, (%rdx)
+#APP
+# 27 "tmul_asm.c" 1
+ setae %al # Set result
+# 0 "" 2
+#NO_APP
+ movzbl %al, %eax
+ ret
+ .cfi_endproc
+.LFE2:
+ .size tmul_ok2, .-tmul_ok2
+ .globl umult_ok
+ .type umult_ok, @function
+umult_ok:
+.LFB3:
+ .cfi_startproc
+ movq %rdx, %rcx
+#APP
+# 41 "tmul_asm.c" 1
+ movq %rdi,%rax #Get x
+ mulq %rsi # Unsigned long mult x*y
+ movq %rax,(%rcx) #Store low-order 8bytes at dest
+ setae %dil #Set result
+# 0 "" 2
+#NO_APP
+ movzbl %dil, %eax
+ ret
+ .cfi_endproc
+.LFE3:
+ .size umult_ok, .-umult_ok
+ .ident "GCC: (GNU) 5.3.1 20160406 (Red Hat 5.3.1-6)"
+ .section .note.GNU-stack,"",@progbits