How to convert from decimal to binary using DEBUG(Assembly)

Thread Starter

metal10

Joined Nov 15, 2009
6
Hello every1, the title basically says it all, so how do i convert from decimal to binary using DEBUG (Assembly)!

org 100h
section .text
start:
mov ax, output
mov bx, [num]
sub dx, dx

I think this code is wrong, ppl plz help me! :confused:
 

Papabravo

Joined Feb 24, 2006
22,116
Wrong for what purpose? After executing three instructions does it go off into the weeds. What do you want it to do exactly?
 

Thread Starter

metal10

Joined Nov 15, 2009
6
come on guys help me, i dont get the assignment and it due tomorow OMG!
I need to convert it from decimal to binary!

It says i need to prompt the user to enter an 4 digit decimal number which should sotre in null terminated string. THan if the user enter fewer than 4 digits before pressing return, then your program should ask for a 4 digit number again. Other wise it should efficiently convert the 4 character numeric string into a 16 bit numeric value and store this in a word variable. Than using a loop, convert the 16 bit value into a 16 character string of 0s and 1s. Store this in another null terminated string. Display the 16 character binary string result.

PPL PLZ HELP ME! ty if done so xD!
 

BMorse

Joined Sep 26, 2009
2,675
Here is what google came up with when doing a search for "Decimal to Binary Conversion in Assembly" :

Rich (BB code):
; Code written by Sanchit Karve
;                   born2c0de
;           printf("I'm a %XR",195936478);
; Target Processor : 16-bit 80x86 Microprocessor or Higher.

; No User Interface code, since this is a code snippet.

; Code can be copied and pasted in your code since
; PUSHA and POPA have been used to prevent changes to
; previous Register Values.

; For use with 32-bit Assemblers, you can also replace
; all registers with 'E' (Eg. SI becomes ESI, AX -> EAX)


; Assumption:
; Value(in decimal) to be converted in Binary should be
; in register SI.
; Move it from Stack or from Variable to SI register
; before using this code.

   PUSHA        
;  SI Contains the Value to be converted.
   MOV BX,80h
   MOV AX,BX
   MOV DX,SI

loop_begin:
   AND DX,AX
   TEST DX,AX
   JZ jump_ahead
   XOR DX,DX
   INC DX

jump_ahead:
   PUSHA

;  Call Output Function or INT21h, and pass value
;  stored in DX as output.
;  If you're planning to pass it as an argument to a
;  function, use PUSH DX to pass it via stack.
;  Remember to shift the SP (or BP if you're opening
;  stack frame) accordingly up the stack after the
;  number has been displayed by the function.

   POPA
   MOV DX,SI
   MOV AX,BX
   SHR AX,1
   MOV BX,AX
   TEST BX,BX
   JNZ loop_begin
   POPA
 

BMorse

Joined Sep 26, 2009
2,675
this one doesnt work, any others!

For one, what processor are you programming this for???

And explain why "this one doesn't work"....

If you can not elaborate on what you are doing and on what, then try using google to do your own homework.....
 
Top