Thread: Assembler Help

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    Assembler Help

    Can anyone help me on this problem? I am trying to divide a negative and a posive number in asembler using the IDIV command. Say i divide -9/3 the result should be -3, but it outputs a strange number?
    Any ideas? Much help appreciated.

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You're probably not promoting the ax/eax sign into dx/edx. Using 32bits, it'd should look something like -

    Code:
    	int i=3;
    	int j=-9;
    
    	_asm
    	{		
    		mov eax,j
    		cdq
    		idiv i
    		mov j,eax
    	}

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    Thanks

    Thanks, that works for 32bit, but it has got to be done in 8086 16bit; with the correct answer for any combination of positive or negative numbers. It is really annoying me this.

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Then try -

    Code:
    _asm
    	{		
    		mov ax,-9
                    cwd
    		idiv i
    		mov j,ax
    	}

  5. #5
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Cheers, soz to blother you again is the remainder still being stored in the ah register i'm using this code to get it out:

    short r;

    mov cl,ah
    mov r, cx

  6. #6
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Got!!! Remainder stored in dx. Thanks for your help, how do you learn this???
    V.greatful!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Assembler in GCC
    By Magos in forum Linux Programming
    Replies: 4
    Last Post: 11-05-2002, 04:22 PM
  3. assembler and linker stuff...question
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 12-17-2001, 12:10 AM
  4. MAINFRAME Assembler.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-05-2001, 05:32 PM
  5. interfacing assembler with c++
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-24-2001, 12:13 AM