-
Notifications
You must be signed in to change notification settings - Fork 6
/
move3.s
80 lines (53 loc) · 2.06 KB
/
move3.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# asmsyntax=as
# Presun bloku dat.
#
# Autor: Pavel Tišnovský
# Linux kernel system call table
sys_exit=93
sys_write=64
# List of syscalls for AArch64:
# https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/unistd.h
# počet bajtu
rep_count = 13
# Deklarace makra pro ukonceni aplikace
.macro exit
mov x8, #sys_exit // číslo sycallu pro funkci "exit"
mov x0, #0 // exit code = 0
svc 0 // volání Linuxového kernelu
.endm
# Deklarace makra pro vytisteni zpravy na standardni vystup
.macro writeMessage message,messageLength
mov x8, #sys_write // číslo sycallu pro funkci "write"
mov x0, #1 // standardni vystup
ldr x1, =\message // adresa řetězce, ktery se ma vytisknout
mov x2, #\messageLength // počet znaku, ktere se maji vytisknout
svc 0 // volání Linuxového kernelu
.endm
# Deklarace makra pro presun bloku
.macro moveBlock from,to,length
ldr x1, =\from // adresa bloku pro cteni
ldr x2, =\to // adresa bloku pro zapis
mov x4, #\length // počet bajtu
loop:
ldrb w3, [x1], 1 // cteni bajtu
strb w3, [x2], 1 // zapis bajtu
sub x4, x4, #1 // zmenseni pocitadla
cbnz x4, loop // pokud jsme se nedostali k nule, skok na zacatek smycky
.endm
#-----------------------------------------------------------------------------
.section .data
hello_lbl:
.string "Hello World!\n"
buffer:
.string "************\n"
#-----------------------------------------------------------------------------
.section .bss
#-----------------------------------------------------------------------------
.section .text
.global _start // tento symbol má být dostupný i linkeru
_start:
writeMessage buffer, rep_count
moveBlock hello_lbl, buffer, rep_count
moveBlock hello_lbl, buffer, rep_count
writeMessage buffer, rep_count
exit