-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.s
More file actions
56 lines (43 loc) · 987 Bytes
/
Copy pathmain.s
File metadata and controls
56 lines (43 loc) · 987 Bytes
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
.global _start
.section .rodata
str1:
.byte 32
.ascii "CS166 project. Input something:\n"
str2:
.byte 11
.ascii "You typed: "
str3:
.byte 18
.ascii " characters long.\n"
str4: # used by "you_should_never_call_this()"
.byte 37
.ascii "You should never call this function!\n"
# =============================================================================
.text
_start:
subq $8, %rsp # align the stack for function calls
callq func
movq $60, %rax
xorq %rdi, %rdi
syscall
func:
subq $40, %rsp # allocate 40 bytes
leaq str1(%rip), %rdi
callq print
leaq 1(%rsp), %rdi
callq readline
movb %al, (%rsp)
movq %rax, %rdi
callq print_u64
leaq str3(%rip), %rdi
callq print
leaq str2(%rip), %rdi
callq print
movq %rsp, %rdi
callq print
callq print_newline
addq $40, %rsp
retq
you_should_never_call_this:
leaq str4(%rip), %rdi
jmp print