Assembler - binary

This is a discussion on Assembler - binary within the C++ Programming forums, part of the General Programming Boards category; Can anyone help me out with this, b v.greatful. I'm trying to convert a given int to a binary number. ...

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

    Assembler - binary

    Can anyone help me out with this, b v.greatful. I'm trying to convert a given int to a binary number. I can output the data by dividing the num by 2 each time, e.g
    10/2 = 0
    5/2 = 1
    2/2 = 0
    1/2 =1
    Program outputs 0101, but this has to be revesed so 1010. any ideas? Please!!!

    void DecBinary(short int Num1)
    {
    short int Temp,Answer=0;

    asm
    {
    mov ax,Num1;
    mov Temp,ax;
    Binary:
    mov Answer,0;
    mov bx,2;
    xor ax,ax;
    mov ax,Temp;
    div bl;
    mov bl,al //get whole no out of al
    mov Temp,bx;

    cmp ah,0;
    jz NotNum;
    jmp Next;

    NotNum:
    inc Answer;
    }

    asm
    {
    Next:
    }

    cout << Answer;

    asm
    {
    cmp Temp,0;
    jne Binary;
    }
    }

  2. #2
    Unregistered
    Guest

    help for ya

    you could use push/pop to push the # on stack and then pop the # off when you need to. The would display in opposite order...that is just one way to do it

  3. #3
    Snior Member
    Join Date
    Jan 2002
    Posts
    982
    An example -

    Code:
    #include <cstdio> 
    using namespace std;
    
    int main()
    {
    	int i = 123;
    	char* form = "%d";
    	_asm
    	{
    		mov eax,i
    		mov ecx,32
    bin:		
                    mov ebx,eax
    		and ebx,0x00000001
    		push ebx
    		shr eax,1
                    loop bin
    		mov ecx,32
    print:	
    		pop eax
    		mov ebx,form
    		push ecx
    		push eax
    		push ebx
    		call printf
    		add esp,8
    		pop ecx
    		loop print        
         }
    
    	return 0;
    }

  4. #4
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359

    Cool Thanks

    Thanks for everyones help. Tried push and pop, works on win98 my system, but crashes on an nt system. can't understand why???
    Anyway cheers.

  5. #5
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    What language is that (Assembly) and where can i read up on it?
    I see it when I use my debug program.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  6. #6
    Amo ftbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Read this. It's pretty good. But, you have to come here to get it cause it is over the limit for a file size. http://www.flashdaddee.com/forums/sh...&threadid=1235

  7. #7
    Nor
    Nor is offline
    h ֆhr s Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    thx
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Converting Assembler Operators to Binary
    By sean in forum C Programming
    Replies: 10
    Last Post: 06-06-2002, 02:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21