Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Assembly program crashes with push command

    For some reason my program is crashing after it does everything correct, if I take out the push to EAX it doesn't crash. Can anyone tell me why it's doing this? I have to use push and pop, I cannot use arrays. I have to be able to pop the numbers from EAX to use later on to convert to hex, binary and decimal and show the sum.

    Code:
    TITLE Numfun	 (numfun.asm)
    
    INCLUDE Irvine32.inc
    
    TAB = 9	 ; ASCII code for Tab
    
    .data
    COUNT	DWORD ?
    prompt1 BYTE "How many integers would you like to enter? ",0
    prompt2 BYTE "Please enter an integer: ",0
    str1	BYTE "The sum of the integers is: ",0
    
    .code
    main PROC
    
    mov		EAX,0
    mov		EBX,0
    mov		ECX,0
    mov		EDX,0
    call Prompt
    
    exit
    main ENDP
    
    ;---------------------------------------------------------
    Prompt PROC
    ; Prompts user to input the number of integers they would 
    ; like to use, then asks user for each of the numbers.
    ; Receives: prompt1
    ; Returns: COUNT, 
    ;---------------------------------------------------------
    
    	mov		edx,OFFSET prompt1     ; ask user for input
    	call	        WriteString
    	call	        ReadInt		             ; read character into EAX
    	mov		COUNT,EAX		     ; input integer into COUNT
    	mov		ECX,COUNT		     ; move integer into ECX
    
    L1:
    	mov		edx,OFFSET prompt2
    	call	        WriteString
    	call	        ReadInt
    	add		EBX,EAX
    	push	        EAX
    	call	        Crlf				     ; new line
    	call	        DumpRegs                    ; just to view registers, remove later
    	call	        Crlf				     ; new line
    	loop	L1
    
    	
    
    	ret
    	Prompt ENDP
    
    
    
    ; Display the integer in decimal, hexadecimal, and binary
    ;L2:
    	;mov		ECX,COUNT
    	;pop		EAX
    	;call		WriteHex				; display in hexadecimal
    	;call		TAB
    	;call		WriteBin				; display in binary
    	;call		TAB
    	;call		WriteInt				; display in signed decimal
    	;Loop		L2						; repeat the loop
    
    ;call Crlf					; new line
    
    
    END main

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    When your sub-routine/procedure is called, the return address is placed on the stack. When you push a value onto the stack in your sub-routine/procedure, the ret(urn) statement tries to use that value as the return address.

    Whatever you are trying to do with your data, your sub-routine/procedure must leave the stack in the same state, with the return address as the last entry, when it returns as when it was called.
    Last edited by CFMaBiSmAd; 09-15-2013 at 05:50 AM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    How do I fix the problem? Thank you for your help.

    Quote Originally Posted by CFMaBiSmAd View Post
    When your sub-routine/procedure is called, the return address is placed on the stack. When you push a value onto the stack in your sub-routine/procedure, the ret(urn) statement tries to use that value as the return address.

    Whatever you are trying to do with your data, your sub-routine/procedure must leave the stack in the same state, with the return address as the last entry, when it returns as when it was called.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    You would either return the value in a register or in a location defined by the calling code.

    See the Returning Values from Functions section at the following link - http://www.lahey.com/docs/lfenthelp/F95UGMLPDLLAssy.htm
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •