asm/get_sp.asm
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sat, 13 Dec 2008 17:57:57 +0100
changeset 5 d752cbe8208e
child 9 c3fecc82ade6
permissions -rw-r--r--
asm and parser demos added committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
;;
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
;;  $ID$
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
;;  $Source: /development/c/asm/get_sp.asm,v $
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
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
%include "asm/tools.inc"
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
segment .data
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
label1  	db  			"NASM Powered...", 10, 0
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
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
    12
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
    13
trace_fmt	db				"[EBP-20] = %08x", 10, \
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
							"[EBP-16] = %08x", 10, "[EBP-12] = %08x", 10, \
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
							"[EBP- 8] = %08x", 10, "[EBP- 4] = %08x", 10, \
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
							"[EBP+ 0] = %08x", 10, "[EBP+ 4] = %08x", 10, \
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
							"[EBP+ 8] = %08x", 10, "[EBP+12] = %08x", 10, \
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
							"[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
    19
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
segment .bss
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
	savexp resd 1			;; uninitialized dword value
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
							;; currently not used
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
segment .text
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
	global get_sp
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
get_sp:
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
	enter 4,0				;; push ebp		;; Save Base-Pointer
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
							;; mov ebp, esp ;; Copy Stackpointer for !!local usage!!
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
							;; sub esp, 4   ;; Make room for 1 DWORD
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
	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
    33
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
	push DWORD label1
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
	call printf
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
	add esp, byte 4			;; remove label1 from stack
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
	call stack_trace
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
	call reg_info
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
	call stack_info
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    42
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    43
	call reg_info
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    44
	call stack_info
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    45
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    46
	call stack_trace
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    47
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    48
	;; clean up
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
	mov eax, [ebp-4]		;; return local var
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
	leave 					;; mov esp, ebp pop ebp
d752cbe8208e asm and parser demos added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
	ret						;; return eax