asm/get_sp.asm
changeset 5 d752cbe8208e
child 9 c3fecc82ade6
equal deleted inserted replaced
4:236f8f747073 5:d752cbe8208e
       
     1 ;;
       
     2 ;;  $ID$
       
     3 ;;  $Source: /development/c/asm/get_sp.asm,v $
       
     4 ;;	
       
     5 ;;
       
     6 
       
     7 %include "asm/tools.inc"
       
     8 
       
     9 segment .data
       
    10 label1  	db  			"NASM Powered...", 10, 0
       
    11 reg_format	db				"EAX=%08x EBX=%08x ECX=%08x EDX=%08x", 10, 0
       
    12 st_format	db				"EBP=%08x ESP=%08x ESI=%08x EDI=%08x", 10, 10, 0
       
    13 trace_fmt	db				"[EBP-20] = %08x", 10, \
       
    14 							"[EBP-16] = %08x", 10, "[EBP-12] = %08x", 10, \
       
    15 							"[EBP- 8] = %08x", 10, "[EBP- 4] = %08x", 10, \
       
    16 							"[EBP+ 0] = %08x", 10, "[EBP+ 4] = %08x", 10, \
       
    17 							"[EBP+ 8] = %08x", 10, "[EBP+12] = %08x", 10, \
       
    18 							"[EBP+16] = %08x", 10, "[EBP+20] = %08x", 10, 10, 0
       
    19 
       
    20 segment .bss
       
    21 	savexp resd 1			;; uninitialized dword value
       
    22 							;; currently not used
       
    23 
       
    24 segment .text
       
    25 	global get_sp
       
    26 
       
    27 get_sp:
       
    28 	enter 4,0				;; push ebp		;; Save Base-Pointer
       
    29 							;; mov ebp, esp ;; Copy Stackpointer for !!local usage!!
       
    30 							;; sub esp, 4   ;; Make room for 1 DWORD
       
    31 
       
    32 	mov [ebp-4], esp		;; Store result in !! local variable !!
       
    33 
       
    34 	push DWORD label1
       
    35 	call printf
       
    36 	add esp, byte 4			;; remove label1 from stack
       
    37 
       
    38 	call stack_trace
       
    39 
       
    40 	call reg_info
       
    41 	call stack_info
       
    42 
       
    43 	call reg_info
       
    44 	call stack_info
       
    45 
       
    46 	call stack_trace
       
    47 
       
    48 	;; clean up
       
    49 	mov eax, [ebp-4]		;; return local var
       
    50 	leave 					;; mov esp, ebp pop ebp
       
    51 	ret						;; return eax