Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 12th, 2006, 10:51 AM
Vomster's Avatar
Vomster Vomster is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 158 Vomster User rank is Lance Corporal (50 - 100 Reputation Level)Vomster User rank is Lance Corporal (50 - 100 Reputation Level)Vomster User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 2 h 35 m 58 sec
Reputation Power: 4
ASM - convert number to binary

I need to convert a number to binary. I know that I can take a number and write it to output (in dos) as binary but don't know how to assign that binary number to a variable.

Can someone point me in the right direction?

Code:
INCLUDE Irvine32.inc

CR = 0Dh ;carriage return

LF = 0Ah ;line feed

.data
	myMessage1 BYTE "        Welcome to MyProgram that Multiplies a number",0
	myMessage2 BYTE "       from the keyboard by 26 using the binary Left Shift in Assembler",0
	enterHex BYTE " Please enter a number in hex and I will multiply it by decimal 26: ", 0	
	binMessage BYTE "     The binary number is: ", 0
	hexMessage BYTE "     The hexidemcial number is: ", 0
	decMessage BYTE "     The decimal number is: ", 0	
	num DWORD 0
	
	testMessage BYTE " Please enter your age in hex: ", 0
	
.code
main PROC

 	mov edx,OFFSET myMessage1	; store welcome message address in edx.Use edx register 		
	call WriteString		; Print welcome message
	call Crlf			; new line
	call Crlf			; new line
	
	mov edx,OFFSET myMessage2	; store welcome message address in edx.Use edx register 		
	call WriteString		; Print welcome message
	call Crlf			; new line
	call Crlf			; new line
	call Crlf			; new line
	
	mov edx,OFFSET enterHex		; moves whats in the enterHex to edx
	call WriteString		; prints what is in the edx
	call ReadHex			; reads a hexadecimal integer from the input
	call Crlf			; new line
	call Crlf			; new line	

	mov num,OFFSET enterHex

;MUST CONVERT NUMBER TO BINARY HERE

	mov eax,num			; moves number entered into eax
	mov ebx,num			; moves number entered into ebx
	mov ecx,num			; moves number entered into ecx
	shl eax,4			; shifts left 2 power of 4
	shl ebx,3			; shifts left 2 power of 3
	add eax,ebx			; addes ebx to eax
	shl ecx,1			; shifts left 2 power of 1
	add eax,ecx			; adds ecx to eax
	
	call DumpRegs			; Dump the registers	
	call Crlf			; new line
	call Crlf			; new line
	
	mov edx,OFFSET binMessage 	; moves whats in printBin to edx
	call WriteString		; prints the info stating the number in binary
	mov edx, eax
	call WriteBin			; prints the number in binary
	call Crlf			; new line
	call Crlf			; new line
	
	mov edx,OFFSET hexMessage 	; moves whats in printBin to edx
	call WriteString		; prints the info stating the number in binary
	mov edx, eax
	call WriteHex			; prints the number in binary
	call Crlf			; new line
	call Crlf			; new line
	
	mov edx,OFFSET decMessage 	; moves whats in printBin to edx
	call WriteString		; prints the info stating the number in binary
	mov edx, eax
	call WriteDec			; prints the number in binary
	call Crlf			; new line
	call Crlf			; new line	
		
	call WaitMsg
	exit
main ENDP
END main
__________________

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > ASM - convert number to binary


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway