-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_to_memory.asm
More file actions
51 lines (44 loc) · 1.21 KB
/
add_to_memory.asm
File metadata and controls
51 lines (44 loc) · 1.21 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
.586 ;indicates what assembly is being used
.model flat, stdcall ; specifies memory model
.stack 4096 ; size of stacks in bytes
includelib libcmt.lib ;include these 2 libraries
includelib legacy_stdio_definitions.lib
ExitProcess PROTO, dwExitCode:DWORD ; ExitProcess(DWORD,PROTO)?
extern printf:NEAR
; PROTO sets up a function that will be called w/ argument INVOKE
.data
; variables go here
format dw "x = %d",10,0
.code
increase:
;*a +=1
;take an address as a param so the function is able to change the value store
;at that address
push ebp
mov ebp, esp
mov eax, [ebp+8]
;add +=1
add dword ptr [eax] ,1
;no local vars to clear
pop ebp
ret
main PROC c
push ebp
mov ebp, esp
sub esp, 4
mov dword ptr [ebp-4],15
add esp, 4
;increase &x
;not pushing x, instead pushing its offset (address)
lea eax, ebp-4
push eax
call increase
add esp,4
;printf ("x = %d",x)
push [ebp-4]
push offset format
call printf
add esp, 8
INVOKE ExitProcess,0 ; using () does not work, the equivalent of (0) is , 0
main endp ; there are no blocks, must explicity end main procedure
end