-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStringBasics.s
More file actions
84 lines (59 loc) · 1.18 KB
/
StringBasics.s
File metadata and controls
84 lines (59 loc) · 1.18 KB
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
80
81
82
.data
HelloWorldString:
.asciz "Hello World of Assembly!"
H3110:
.asciz "H3110"
.bss
.lcomm Destination, 100
.lcomm DestinationUsingRep, 100
.lcomm DestinationUsingStos, 100
.text
.globl _start
_start:
nop
# 1. Simple copying using movsb, movsw, movsl
movl $HelloWorldString, %esi
movl $Destination, %edi
movsb
movsw
movsl
# 2. Setting / Clearing the DF flag
std # set the DF flag
cld # clear the DF flag
# 3. Using Rep
movl $HelloWorldString, %esi
movl $DestinationUsingRep, %edi
movl $25, %ecx # set the string length in ECX
cld # clear the DF
rep movsb
std
# 4. Loading string from memory into EAX register
cld
leal HelloWorldString, %esi
lodsb
movb $0, %al
dec %esi
lodsw
movw $0, %ax
subl $2, %esi # Make ESI point back to the original string
lodsl
# 5. Storing strings from EAX to memory
leal DestinationUsingStos, %edi
stosb
stosw
stosl
# 6. Comparing Strings
cld
leal HelloWorldString, %esi
leal H3110, %edi
cmpsb
dec %esi
dec %edi
cmpsw
subl $2, %esi
subl $2, %edi
cmpsl
# The exit() routine
movl $1, %eax
movl $10, %ebx
int $0x80