Can somebody please tell me how to make a loop.

I am trying to convert a decimal number to binary.

I know to divide, and I am putting the remainder on the stack but I have to repeat this until  quotient = 1  (quotient = eax)


    mov eax, 65
    mov ecx, 2
    div ecx
    push  edx

end start:



end start

Posted on 2005-04-13 09:05:53 by luise.valencia


  cmp eax, 1    ; Compare eax to 1
  jne some_label ; Jump if not equal to "some_label"


Posted on 2005-04-13 09:26:31 by Mirno
If you are dividing by 2, why don't you use shift right?
Posted on 2005-04-13 09:33:32 by roticv
C:\Documents.asm(14) : error A2008: syntax error : loop
C:\Documents.asm(8) : error A2081: missing operand after unary operator

.model flat, stdcall
option casemap:none

        mov eax, 65
        mov ecx, 2
        div ecx
        push  edx
        cmp eax, 1
        jne loop

end start
Posted on 2005-04-13 09:34:12 by luise.valencia
What does it do? AS I know Shift right moves the bits to the right and the left most bit goes to the carry flag and the rightmost flas is filled with a 0.

but aritmetically what does it do?
Posted on 2005-04-13 09:35:24 by luise.valencia
loop is an opcode, you can't use it for a label.

Shifting right will divide by two, just as removing the first digit from a decimal number will divide by 10 (no rounding).

If you are converting a number in eax to a binary string, you are probably better off using the shift & carry method.

Posted on 2005-04-13 09:43:37 by Mirno
Can u please explain me a little more about the shift and carry method.

I must convert a float number to binary IEEE.  suppose 3.21 x 10 E 2

I know to convert 3 to binary.  and it fills me the stack with 0 and 1 but I dont know how to retireve those values to a register.

Posted on 2005-04-13 10:03:24 by luise.valencia
he has a whole floating point library useing the FPU
Posted on 2005-04-13 10:14:02 by rob.rice
I cant use FPU
Posted on 2005-04-13 10:52:34 by luise.valencia
Pushing a 32 bit value containing 0 or 1 onto the stack isn't a very clever way of doing something like this.

Create a buffer 33 bytes long (32 bytes for each of the 32 bits you'll put in there and 1 more for the terminator).
Using shift (left or right depending on the order you want them out), move one bit into the carry flag. If the carry flag is set, move a '1' into your buffer, else move a zero. Increment your pointer to your buffer. Repeat until you've gone through all bits.

If you've still not worked out how to convert an integer to a floating point value, maybe you should talk with your professor / teacher.

To be honest, it's not rocket surgery.

Also, don't keep re-registering (I'm guessing you're the same guy as from, it clutters up the database.

Posted on 2005-04-13 11:28:19 by Mirno
I am sorry for registering but I wanted to change my email to get notificacion and I didnt see the option.  AS the other email I will not check it anymore
Posted on 2005-04-13 12:02:29 by luise.valencia