Results 1 to 4 of 4

Thread: desperate help!!!

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    desperate help!!!

    I've been working on this for 12 hours... I dont know why it doesnt work and my instructor hasnt been responding in the past 48hours... someone give me a little hint plz


    Code:
    INCLUDE irvine32.inc
    
    
    .data
    charArr BYTE 2 DUP(?)
    
    
    .code
    main PROC
    ; these just get two character inputs
    	call ReadChar
    	mov  charArr, al
    	call ReadChar
    	mov  [charArr+1], al
    	
    	
    	; push the characters onto the stack
    	push OFFSET [charArr + 1]
    	push OFFSET charArr
    	call swap
    	
    	
    	
    	mov  al, charArr
    	call WriteChar
    	mov  al, [charArr+1]
    	call WriteChar
    main ENDP
    
    
    
    swap PROC
    	push ebp
    	mov  ebp, esp
    
    	
    
    	mov  al, BYTE PTR [ebp+8]
    	mov  bl, BYTE PTR [ebp+12]
    	mov	  [ebp+8],  bl
    	mov	  [ebp+12], al
    	
    	
    	pop  ebp
    	ret 8	
    swap ENDP 
    
    
    END main
    readChar and writeChar are provided in libraries... just read and write chars. uuh it's supposed to swap the two characters stores in the charArr but it doesnt do anything. what's wrong
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945
    I don't know what assembler you are using but from what I can tell your program looks fine. Here is one suggestion though:
    Perhaps you could use the XCHG (exchange (swap) instruction)?
    Also what do you mean it does nothing? Does the pogram hang when executed or does it return the values that it supposed to swap without swapping them?
    Last edited by Peter Swinkels; Nov 23rd, 2004 at 09:01 AM.

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hehe yeah it would display the result without them being swapped... I wrote this afterwards... after turning it in haha. it works:

    Code:
    INCLUDE irvine32.inc
    
    .data
    charArr BYTE 2 DUP(?)
    
    .code
    main PROC
    	; Get two character inputs and save them in a 2-byte array
    	call ReadChar
    	mov  charArr, al
    	call ReadChar
    	mov  [charArr+1], al
    	
    	
    	; push the offsets of characters onto the stack
    	mov eax, OFFSET charArr +1
    	push eax					; second parameter
    	dec  eax
    	push eax					; first parameter
    	
    	call swap2
    	
    	
    	mov  al, charArr
    	call WriteChar
    	mov  al, [charArr+1]
    	call WriteChar
    	
    	exit
    main ENDP
    
    
    swap2 PROC
    	push ebp			; save EBP
    	mov ebp, esp
    		
    	mov eax, [ebp+8]	; offset of first parameter
    						; EBP+8 is an offset. when dereferenced, it points
    						; to the offset of the first array element (yeah, offset of an offset)
    						; EAX has now the offset of the first array element
    	;mov al, [eax]		; this would give the value of the first array element
    	
    	
    	mov bl,	 [eax]		; Value of first parameter
    	mov eax, [ebp+12]	; offset of second parameter
    	xchg [eax],bl		; bl=val of second param. Second param is set to first param.
    	mov eax, [ebp+8]	; offset of first param
    	xchg [eax],bl		; first param is set to second param
    	
    	
    	
    	
    	pop ebp				; restore EBP
    	ret 8
    swap2 ENDP
    END main
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004

    Re: desperate help!!!

    Code:
    	; push the characters onto the stack
    	push OFFSET [charArr + 1]
    	push OFFSET charArr
    	call swap
    Methinks it was the fact that you should have either not have had brackets or had brackets (this fact changes from assembler to assembler.)
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

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



Click Here to Expand Forum to Full Width