author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:51:15 +0200 | |
changeset 80 | 5d7057a1b202 |
parent 9 | c3fecc82ade6 |
child 166 | ecd6492274ad |
permissions | -rw-r--r-- |
5
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
1 |
;; |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
2 |
;; test/demos/asm/get_sp.asm |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
5
diff
changeset
|
3 |
;; Copyright (C) 2008 Markus Broeker |
5
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
;; |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
%include "asm/tools.inc" |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
segment .data |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
label1 db "NASM Powered...", 10, 0 |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
10 |
reg_format db "EAX=%08x EBX=%08x ECX=%08x EDX=%08x", 10, 0 |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
st_format db "EBP=%08x ESP=%08x ESI=%08x EDI=%08x", 10, 10, 0 |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
trace_fmt db "[EBP-20] = %08x", 10, \ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
"[EBP-16] = %08x", 10, "[EBP-12] = %08x", 10, \ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
"[EBP- 8] = %08x", 10, "[EBP- 4] = %08x", 10, \ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
"[EBP+ 0] = %08x", 10, "[EBP+ 4] = %08x", 10, \ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
"[EBP+ 8] = %08x", 10, "[EBP+12] = %08x", 10, \ |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
"[EBP+16] = %08x", 10, "[EBP+20] = %08x", 10, 10, 0 |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
segment .bss |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
savexp resd 1 ;; uninitialized dword value |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
21 |
;; currently not used |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
22 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
segment .text |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
global get_sp |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
25 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
get_sp: |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
enter 4,0 ;; push ebp ;; Save Base-Pointer |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
;; mov ebp, esp ;; Copy Stackpointer for !!local usage!! |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
29 |
;; sub esp, 4 ;; Make room for 1 DWORD |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
mov [ebp-4], esp ;; Store result in !! local variable !! |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
push DWORD label1 |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
call printf |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
add esp, byte 4 ;; remove label1 from stack |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
call stack_trace |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
call reg_info |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
call stack_info |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
call reg_info |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
43 |
call stack_info |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
44 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
45 |
call stack_trace |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
|
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
;; clean up |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
48 |
mov eax, [ebp-4] ;; return local var |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
49 |
leave ;; mov esp, ebp pop ebp |
d752cbe8208e
asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
50 |
ret ;; return eax |