asm/get_sp.asm
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 27 Dec 2013 16:00:09 +0100
changeset 167 7c6b221900bf
parent 166 ecd6492274ad
permissions -rw-r--r--
Proper Datatypes to leave the 80's
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
;;
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
166
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    10
reg_format	db			"EAX=%08x EBX=%08x ECX=%08x EDX=%08x", 10, 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    11
st_format	db			"EBP=%08x ESP=%08x ESI=%08x EDI=%08x", 10, 10, 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    12
trace_fmt	db			"[EBP-20] = %08x", 10, \
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    13
					"[EBP-16] = %08x", 10, "[EBP-12] = %08x", 10, \
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    14
					"[EBP- 8] = %08x", 10, "[EBP- 4] = %08x", 10, \
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    15
					"[EBP+ 0] = %08x", 10, "[EBP+ 4] = %08x", 10, \
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    16
					"[EBP+ 8] = %08x", 10, "[EBP+12] = %08x", 10, \
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    17
					"[EBP+16] = %08x", 10, "[EBP+20] = %08x", 10, 10, 0
5
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
166
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    21
					;; currently not used
5
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:
166
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    27
	enter 4,0			;; push ebp		;; Save Base-Pointer
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    28
					;; mov ebp, esp ;; Copy Stackpointer for !!local usage!!
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    29
					;; sub esp, 4   ;; Make room for 1 DWORD
5
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
166
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    49
	leave 				;; mov esp, ebp pop ebp
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 9
diff changeset
    50
	ret				;; return eax