ARMssembly 3
This commit is contained in:
72
ARMssembly_3/chall_3.S
Executable file
72
ARMssembly_3/chall_3.S
Executable file
@@ -0,0 +1,72 @@
|
||||
.arch armv8-a
|
||||
.file "chall_3.c"
|
||||
.text
|
||||
.align 2
|
||||
.global func1
|
||||
.type func1, %function
|
||||
func1:
|
||||
stp x29, x30, [sp, -48]!
|
||||
add x29, sp, 0
|
||||
str w0, [x29, 28]
|
||||
str wzr, [x29, 44]
|
||||
b .L2
|
||||
.L4:
|
||||
ldr w0, [x29, 28]
|
||||
and w0, w0, 1
|
||||
cmp w0, 0
|
||||
beq .L3
|
||||
ldr w0, [x29, 44]
|
||||
bl func2
|
||||
str w0, [x29, 44]
|
||||
.L3:
|
||||
ldr w0, [x29, 28]
|
||||
lsr w0, w0, 1
|
||||
str w0, [x29, 28]
|
||||
.L2:
|
||||
ldr w0, [x29, 28]
|
||||
cmp w0, 0
|
||||
bne .L4
|
||||
ldr w0, [x29, 44]
|
||||
ldp x29, x30, [sp], 48
|
||||
ret
|
||||
.size func1, .-func1
|
||||
.align 2
|
||||
.global func2
|
||||
.type func2, %function
|
||||
func2:
|
||||
sub sp, sp, #16
|
||||
str w0, [sp, 12]
|
||||
ldr w0, [sp, 12]
|
||||
add w0, w0, 3
|
||||
add sp, sp, 16
|
||||
ret
|
||||
.size func2, .-func2
|
||||
.section .rodata
|
||||
.align 3
|
||||
.LC0:
|
||||
.string "Result: %ld\n"
|
||||
.text
|
||||
.align 2
|
||||
.global main
|
||||
.type main, %function
|
||||
main:
|
||||
stp x29, x30, [sp, -48]!
|
||||
add x29, sp, 0
|
||||
str w0, [x29, 28]
|
||||
str x1, [x29, 16]
|
||||
ldr x0, [x29, 16]
|
||||
add x0, x0, 8
|
||||
ldr x0, [x0]
|
||||
bl atoi
|
||||
bl func1
|
||||
str w0, [x29, 44]
|
||||
adrp x0, .LC0
|
||||
add x0, x0, :lo12:.LC0
|
||||
ldr w1, [x29, 44]
|
||||
bl printf
|
||||
nop
|
||||
ldp x29, x30, [sp], 48
|
||||
ret
|
||||
.size main, .-main
|
||||
.ident "GCC: (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0"
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
Reference in New Issue
Block a user