mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-23 15:36:45 +08:00
corrected error induced by post/pre increment to stack
This commit is contained in:
parent
326fd2ea90
commit
c5143f19db
2 changed files with 100 additions and 100 deletions
|
|
@ -1,103 +1,90 @@
|
||||||
.section __TEXT,__text,regular,pure_instructions
|
.arch armv8-a
|
||||||
.build_version macos, 13, 0 sdk_version 13, 1
|
.file "nine_args.c"
|
||||||
.globl _LessSillyFunction ; -- Begin function LessSillyFunction
|
.text
|
||||||
.p2align 2
|
.section .rodata.str1.8,"aMS",@progbits,1
|
||||||
_LessSillyFunction: ; @LessSillyFunction
|
.align 3
|
||||||
|
.LC0:
|
||||||
|
.string "This example hurts my brain: %ld\n"
|
||||||
|
.text
|
||||||
|
.align 2
|
||||||
|
.global LessSillyFunction
|
||||||
|
.type LessSillyFunction, %function
|
||||||
|
LessSillyFunction:
|
||||||
|
.LFB23:
|
||||||
.cfi_startproc
|
.cfi_startproc
|
||||||
; %bb.0:
|
stp x29, x30, [sp, -16]!
|
||||||
sub sp, sp, #96
|
.cfi_def_cfa_offset 16
|
||||||
stp x29, x30, [sp, #80] ; 16-byte Folded Spill
|
.cfi_offset 29, -16
|
||||||
add x29, sp, #80
|
.cfi_offset 30, -8
|
||||||
.cfi_def_cfa w29, 16
|
mov x29, sp
|
||||||
.cfi_offset w30, -8
|
mov x2, x7
|
||||||
.cfi_offset w29, -16
|
adrp x1, .LC0
|
||||||
stur x0, [x29, #-8]
|
add x1, x1, :lo12:.LC0
|
||||||
stur x1, [x29, #-16]
|
mov w0, 1
|
||||||
stur x2, [x29, #-24]
|
bl __printf_chk
|
||||||
stur x3, [x29, #-32]
|
ldp x29, x30, [sp], 16
|
||||||
str x4, [sp, #40]
|
.cfi_restore 30
|
||||||
str x5, [sp, #32]
|
.cfi_restore 29
|
||||||
str x6, [sp, #24]
|
.cfi_def_cfa_offset 0
|
||||||
str x7, [sp, #16]
|
|
||||||
ldr x8, [sp, #16]
|
|
||||||
mov x9, sp
|
|
||||||
str x8, [x9]
|
|
||||||
adrp x0, l_.str@PAGE
|
|
||||||
add x0, x0, l_.str@PAGEOFF
|
|
||||||
bl _printf
|
|
||||||
ldp x29, x30, [sp, #80] ; 16-byte Folded Reload
|
|
||||||
add sp, sp, #96
|
|
||||||
ret
|
ret
|
||||||
.cfi_endproc
|
.cfi_endproc
|
||||||
; -- End function
|
.LFE23:
|
||||||
.globl _SillyFunction ; -- Begin function SillyFunction
|
.size LessSillyFunction, .-LessSillyFunction
|
||||||
.p2align 2
|
.section .rodata.str1.8
|
||||||
_SillyFunction: ; @SillyFunction
|
.align 3
|
||||||
|
.LC1:
|
||||||
|
.string "This example hurts my brain: %ld %ld\n"
|
||||||
|
.text
|
||||||
|
.align 2
|
||||||
|
.global SillyFunction
|
||||||
|
.type SillyFunction, %function
|
||||||
|
SillyFunction:
|
||||||
|
.LFB24:
|
||||||
.cfi_startproc
|
.cfi_startproc
|
||||||
; %bb.0:
|
stp x29, x30, [sp, -16]!
|
||||||
sub sp, sp, #112
|
.cfi_def_cfa_offset 16
|
||||||
stp x29, x30, [sp, #96] ; 16-byte Folded Spill
|
.cfi_offset 29, -16
|
||||||
add x29, sp, #96
|
.cfi_offset 30, -8
|
||||||
.cfi_def_cfa w29, 16
|
mov x29, sp
|
||||||
.cfi_offset w30, -8
|
mov x2, x7
|
||||||
.cfi_offset w29, -16
|
ldr x3, [sp, 16]
|
||||||
ldr x8, [x29, #16]
|
adrp x1, .LC1
|
||||||
stur x0, [x29, #-8]
|
add x1, x1, :lo12:.LC1
|
||||||
stur x1, [x29, #-16]
|
mov w0, 1
|
||||||
stur x2, [x29, #-24]
|
bl __printf_chk
|
||||||
stur x3, [x29, #-32]
|
ldp x29, x30, [sp], 16
|
||||||
stur x4, [x29, #-40]
|
.cfi_restore 30
|
||||||
str x5, [sp, #48]
|
.cfi_restore 29
|
||||||
str x6, [sp, #40]
|
.cfi_def_cfa_offset 0
|
||||||
str x7, [sp, #32]
|
|
||||||
str x8, [sp, #24]
|
|
||||||
ldr x10, [sp, #32]
|
|
||||||
ldr x8, [sp, #24]
|
|
||||||
mov x9, sp
|
|
||||||
str x10, [x9]
|
|
||||||
str x8, [x9, #8]
|
|
||||||
adrp x0, l_.str.1@PAGE
|
|
||||||
add x0, x0, l_.str.1@PAGEOFF
|
|
||||||
bl _printf
|
|
||||||
ldp x29, x30, [sp, #96] ; 16-byte Folded Reload
|
|
||||||
add sp, sp, #112
|
|
||||||
ret
|
ret
|
||||||
.cfi_endproc
|
.cfi_endproc
|
||||||
; -- End function
|
.LFE24:
|
||||||
.globl _main ; -- Begin function main
|
.size SillyFunction, .-SillyFunction
|
||||||
.p2align 2
|
.align 2
|
||||||
_main: ; @main
|
.global main
|
||||||
|
.type main, %function
|
||||||
|
main:
|
||||||
|
.LFB25:
|
||||||
.cfi_startproc
|
.cfi_startproc
|
||||||
; %bb.0:
|
stp x29, x30, [sp, -16]!
|
||||||
sub sp, sp, #32
|
.cfi_def_cfa_offset 16
|
||||||
stp x29, x30, [sp, #16] ; 16-byte Folded Spill
|
.cfi_offset 29, -16
|
||||||
add x29, sp, #16
|
.cfi_offset 30, -8
|
||||||
.cfi_def_cfa w29, 16
|
mov x29, sp
|
||||||
.cfi_offset w30, -8
|
mov x3, 9
|
||||||
.cfi_offset w29, -16
|
mov x2, 8
|
||||||
mov x9, sp
|
adrp x1, .LC1
|
||||||
mov x8, #9
|
add x1, x1, :lo12:.LC1
|
||||||
str x8, [x9]
|
mov w0, 1
|
||||||
mov x0, #1
|
bl __printf_chk
|
||||||
mov x1, #2
|
mov w0, 0
|
||||||
mov x2, #3
|
ldp x29, x30, [sp], 16
|
||||||
mov x3, #4
|
.cfi_restore 30
|
||||||
mov x4, #5
|
.cfi_restore 29
|
||||||
mov x5, #6
|
.cfi_def_cfa_offset 0
|
||||||
mov x6, #7
|
|
||||||
mov x7, #8
|
|
||||||
bl _SillyFunction
|
|
||||||
mov w0, #0
|
|
||||||
ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
|
|
||||||
add sp, sp, #32
|
|
||||||
ret
|
ret
|
||||||
.cfi_endproc
|
.cfi_endproc
|
||||||
; -- End function
|
.LFE25:
|
||||||
.section __TEXT,__cstring,cstring_literals
|
.size main, .-main
|
||||||
l_.str: ; @.str
|
.ident "GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
|
||||||
.asciz "This example hurts my brain: %ld\n"
|
.section .note.GNU-stack,"",@progbits
|
||||||
|
|
||||||
l_.str.1: ; @.str.1
|
|
||||||
.asciz "This example hurts my brain: %ld %ld\n"
|
|
||||||
|
|
||||||
.subsections_via_symbols
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,30 @@
|
||||||
.text
|
.text
|
||||||
.global main
|
.global main
|
||||||
|
|
||||||
|
/* Demonstration of using more than 8 arguments to a function. This
|
||||||
|
demo is LINUX only as APPLE will put all arguments beyond the first
|
||||||
|
one on the stack anyway.
|
||||||
|
|
||||||
|
On LINUX, all parameters to a function beyond the eight go on the
|
||||||
|
stack. The first 8 go in registers x0 through x7 as normal (for
|
||||||
|
LINUX).
|
||||||
|
*/
|
||||||
|
|
||||||
SillyFunction:
|
SillyFunction:
|
||||||
str x30, [sp, -16]!
|
stp x29, x30, [sp, -16]! // Changes sp.
|
||||||
|
mov x29, sp
|
||||||
ldr x0, =fmt
|
ldr x0, =fmt
|
||||||
mov x1, x7
|
mov x1, x7
|
||||||
ldr x2, [sp, 16]
|
ldr x2, [sp, 16] // This does not alter the sp.
|
||||||
bl printf
|
bl printf
|
||||||
ldr x30, [sp], 32
|
ldp x29, x30, [sp], 16 // Undoes change to sp.
|
||||||
ret
|
ret
|
||||||
|
|
||||||
main:
|
main:
|
||||||
str x30, [sp, -16]!
|
stp x29, x30, [sp, -16]! // sp down total of 16.
|
||||||
|
mov x29, sp
|
||||||
mov x0, 9
|
mov x0, 9
|
||||||
str x0, [sp, -16]!
|
str x0, [sp, -16]! // sp down total of 32.
|
||||||
mov x0, 1
|
mov x0, 1
|
||||||
mov x1, 2
|
mov x1, 2
|
||||||
mov x2, 3
|
mov x2, 3
|
||||||
|
|
@ -23,7 +34,9 @@ main:
|
||||||
mov x6, 7
|
mov x6, 7
|
||||||
mov x7, 8
|
mov x7, 8
|
||||||
bl SillyFunction
|
bl SillyFunction
|
||||||
ldr x30, [sp], 32
|
add sp, sp, 16 // undoes change of sp by 16 due
|
||||||
|
// to function call.
|
||||||
|
ldp x29, x30, [sp], 16 // undoes change to sp of 16.
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.data
|
.data
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue