
September 12th, 2006, 10:51 AM
|
 |
Contributing User
|
|
Join Date: Feb 2005
Posts: 158
 
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
__________________
|