-
Notifications
You must be signed in to change notification settings - Fork 2
/
nrc_complicated.asm
103 lines (83 loc) · 1.58 KB
/
nrc_complicated.asm
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
global _start
extern _GetStdHandle@4
extern _WriteFile@20
extern _ExitProcess@4
section .text
not_ret_func1:
mov eax, 10
pop eax
ret
not_ret_func2:
mov eax, 20
ret
not_returned:
mov ebp, esp
sub esp, 4
push 0
lea eax, [ebp - 4]
push eax
push (not_return_msg_end - not_return_msg)
push not_return_msg
push ebx
call _WriteFile@20
call exit
ret
nothing_to_do_func:
ret
exit:
; ExitProcess(0)
push 0
call _ExitProcess@4
ret
main:
; DWORD bytes;
; index variable;
mov ebp, esp
sub esp, 4
mov dword [ebp - 8], 0
; DWORD bytes;
; <- prepare local variable
sub esp, 4
; prepare for non-returning calls
push not_returned
push not_ret_func2
; hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)
; (STD_OUTPUT_HANDLE = -11)
push -11
call _GetStdHandle@4
mov ebx, eax
loop:
; show 'Hello, World'
; WriteFile( hStdOut, msg, length(msg), &size, 0)
push 0
lea eax, [ebp - 4]
push eax
push (message_end - message)
push message
push ebx
call _WriteFile@20
call not_ret_func1
; Never execute below
dumy:
db 'Hello, World', 10
dumy_end:
; i += 1
mov eax, dword [ebp - 8]
add eax, 1
mov dword [ebp - 8], eax
; jmp loop if i < 0x20
cmp dword [ebp - 8], 0x20
jl loop
call exit
; never here
hlt
; Entry point
_start:
call main
ret
message:
db 'Hello, World', 10
message_end:
not_return_msg:
db 'Not Returning', 10
not_return_msg_end: