corrected error induced by post/pre increment to stack

This commit is contained in:
Perry Kivolowitz 2024-06-21 10:54:55 -05:00
parent 326fd2ea90
commit c5143f19db
2 changed files with 100 additions and 100 deletions

View file

@ -1,103 +1,90 @@
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 13, 0 sdk_version 13, 1
.globl _LessSillyFunction ; -- Begin function LessSillyFunction
.p2align 2
_LessSillyFunction: ; @LessSillyFunction
.arch armv8-a
.file "nine_args.c"
.text
.section .rodata.str1.8,"aMS",@progbits,1
.align 3
.LC0:
.string "This example hurts my brain: %ld\n"
.text
.align 2
.global LessSillyFunction
.type LessSillyFunction, %function
LessSillyFunction:
.LFB23:
.cfi_startproc
; %bb.0:
sub sp, sp, #96
stp x29, x30, [sp, #80] ; 16-byte Folded Spill
add x29, sp, #80
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
stur x0, [x29, #-8]
stur x1, [x29, #-16]
stur x2, [x29, #-24]
stur x3, [x29, #-32]
str x4, [sp, #40]
str x5, [sp, #32]
str x6, [sp, #24]
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
stp x29, x30, [sp, -16]!
.cfi_def_cfa_offset 16
.cfi_offset 29, -16
.cfi_offset 30, -8
mov x29, sp
mov x2, x7
adrp x1, .LC0
add x1, x1, :lo12:.LC0
mov w0, 1
bl __printf_chk
ldp x29, x30, [sp], 16
.cfi_restore 30
.cfi_restore 29
.cfi_def_cfa_offset 0
ret
.cfi_endproc
; -- End function
.globl _SillyFunction ; -- Begin function SillyFunction
.p2align 2
_SillyFunction: ; @SillyFunction
.LFE23:
.size LessSillyFunction, .-LessSillyFunction
.section .rodata.str1.8
.align 3
.LC1:
.string "This example hurts my brain: %ld %ld\n"
.text
.align 2
.global SillyFunction
.type SillyFunction, %function
SillyFunction:
.LFB24:
.cfi_startproc
; %bb.0:
sub sp, sp, #112
stp x29, x30, [sp, #96] ; 16-byte Folded Spill
add x29, sp, #96
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
ldr x8, [x29, #16]
stur x0, [x29, #-8]
stur x1, [x29, #-16]
stur x2, [x29, #-24]
stur x3, [x29, #-32]
stur x4, [x29, #-40]
str x5, [sp, #48]
str x6, [sp, #40]
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
stp x29, x30, [sp, -16]!
.cfi_def_cfa_offset 16
.cfi_offset 29, -16
.cfi_offset 30, -8
mov x29, sp
mov x2, x7
ldr x3, [sp, 16]
adrp x1, .LC1
add x1, x1, :lo12:.LC1
mov w0, 1
bl __printf_chk
ldp x29, x30, [sp], 16
.cfi_restore 30
.cfi_restore 29
.cfi_def_cfa_offset 0
ret
.cfi_endproc
; -- End function
.globl _main ; -- Begin function main
.p2align 2
_main: ; @main
.LFE24:
.size SillyFunction, .-SillyFunction
.align 2
.global main
.type main, %function
main:
.LFB25:
.cfi_startproc
; %bb.0:
sub sp, sp, #32
stp x29, x30, [sp, #16] ; 16-byte Folded Spill
add x29, sp, #16
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16
mov x9, sp
mov x8, #9
str x8, [x9]
mov x0, #1
mov x1, #2
mov x2, #3
mov x3, #4
mov x4, #5
mov x5, #6
mov x6, #7
mov x7, #8
bl _SillyFunction
mov w0, #0
ldp x29, x30, [sp, #16] ; 16-byte Folded Reload
add sp, sp, #32
stp x29, x30, [sp, -16]!
.cfi_def_cfa_offset 16
.cfi_offset 29, -16
.cfi_offset 30, -8
mov x29, sp
mov x3, 9
mov x2, 8
adrp x1, .LC1
add x1, x1, :lo12:.LC1
mov w0, 1
bl __printf_chk
mov w0, 0
ldp x29, x30, [sp], 16
.cfi_restore 30
.cfi_restore 29
.cfi_def_cfa_offset 0
ret
.cfi_endproc
; -- End function
.section __TEXT,__cstring,cstring_literals
l_.str: ; @.str
.asciz "This example hurts my brain: %ld\n"
l_.str.1: ; @.str.1
.asciz "This example hurts my brain: %ld %ld\n"
.subsections_via_symbols
.LFE25:
.size main, .-main
.ident "GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
.section .note.GNU-stack,"",@progbits

View file

@ -1,19 +1,30 @@
.text
.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:
str x30, [sp, -16]!
stp x29, x30, [sp, -16]! // Changes sp.
mov x29, sp
ldr x0, =fmt
mov x1, x7
ldr x2, [sp, 16]
ldr x2, [sp, 16] // This does not alter the sp.
bl printf
ldr x30, [sp], 32
ldp x29, x30, [sp], 16 // Undoes change to sp.
ret
main:
str x30, [sp, -16]!
stp x29, x30, [sp, -16]! // sp down total of 16.
mov x29, sp
mov x0, 9
str x0, [sp, -16]!
str x0, [sp, -16]! // sp down total of 32.
mov x0, 1
mov x1, 2
mov x2, 3
@ -23,7 +34,9 @@ main:
mov x6, 7
mov x7, 8
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
.data