Main Menu

Home
MASM
C
C/MASM
Java
Google
 
Home arrow MASM arrow Print Number In Hexadecimal
Print Number In Hexadecimal
 TITLE Print Number in Hex

; This program reads a signed decimal number into a 32-bit double word and
; then prints out the double word in hexadecimal, one hex character at a time.

INCLUDE Irvine32.inc
.data
promptUserForDec BYTE "Enter a signed decimal number: ",0
numberConverted  BYTE "Your number in hex is: ",0
tryAgain   BYTE "Try again (y or n): ",0
decimalToConvert DWORD ?


.code
Main PROC
 Convert:
 mov edx,OFFSET promptUserForDec  ;Prompt user for signed decimal number
 call WriteString
 
 call ReadInt      ;Get signed decimal number from user
 call crlf
 mov edx,eax
 
 mov cl,32
 mov ebx,8       ;Convert signed decimal to hexadecimal and print
 OneConversion:
 sub cl,4
 mov eax,edx
 shr eax,cl
 and al,00001111b
 add al,30h
 cmp al,39h
 jbe Over
 add al,7h
 Over:
 call WriteChar
 sub ebx,1
 cmp ebx,0
 jne OneConversion
 
 mov al,68h
 call WriteChar
 
 call crlf
 call crlf
 
 mov edx,OFFSET tryAgain    ;Try again
 call WriteString
 call ReadChar
 call crlf
 call crlf
 cmp al,79h
 je Convert

 exit
main ENDP

 

END main
 
< Prev   Next >
© 2009 SourceRip
Joomla! is Free Software released under the GNU/GPL License.