News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Simple decimal string to hex string demo.

Started by hutch--, November 06, 2006, 09:33:54 AM

Previous topic - Next topic

hutch--

One of our members asked about how to do this and as I have seen the question before, here is a simple demo using two of the masm32 library procedures to do this.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    ascnum2hex PROTO :DWORD,:DWORD

    .data
      item db "1234",0  ; zero terminated ascii string with numbers

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL buffer[32]:BYTE   ; buffer to write result to.

    print ADDR item," input DECIMAL string",13,10

    invoke ascnum2hex,ADDR item,ADDR buffer

    print ADDR buffer," output HEX string",13,10

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

ascnum2hex proc pString:DWORD,pTarget:DWORD

  ; ----------------------------------------------------------------------
  ; convert string to a DWORD sized number with result in the EAX register
  ; ----------------------------------------------------------------------
    invoke atodw, pString

  ; ---------------------------------------------
  ; rewrite the result back to the target address
  ; ---------------------------------------------
    invoke dw2hex_ex,eax,pTarget

    ret

ascnum2hex endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

EddieB

Thats just what I needed, Thank you ever so much.

Cheers,
Eddie

dirigo

Hi ... newbie here.

I tried assembling the above code using the MASM32 Editor and received the following assembly errors:

D:\masm32\testasmprogs\asc2hex.asm(22) : error A2008: syntax error : inkey
D:\masm32\testasmprogs\asc2hex.asm(53) : error A2006: undefined symbol : dv2hex_ex

Yes, I assembled it per instruction meaning "Console Assembly and Link"  (the MSDOS window has a title of 'buildc').

I figure the errors resulted because I did something incorrect.  I just copied the code directly over from this web page ... it only had one "include" ('include \masm32\include\masm32rt.inc') listed in the actual program text".  Was I suppose to include a bunch of other "includes" as well?

Thanks in advance. 

dirigo

Hi again  :bg

I "think" I need to get an updated version of macros.asm.  Searching the forum seems to indicate "inkey" macro was added to macros.asm at some later date than when I first downloaded the MASM kit and kaboddle (around May, 2005 ... yeah, I'm 'sort of' just getting started!).  So I'll continue to look for an updated macros.asm file.  I found an updated windows,inc file (version 1.33) (I currently have version 1.28 installed) and downloaded it.  Can I simply delete the older version and replace it with the newer version, i.e., 1.33 version?  Seems plausible, but ... LOL!

Also, is it possible that "dv2hex_ex" is a typo?  I found in the current file, macros.asm, references to atodw and dw2hex.

Now off to find the newer macros.asm file version.


hutch--

dirigo,

Just make sure you have the current version of masm32 Version 9.0. The macros.asm file assumes a number of things available that were not in earlier version like the MSVCRT library and some of the modules in the masm32 library. The "inkey" macro uses both MSVCRT and a module in the masm32 library, the dw2hex_ex is a table driven module in the masm32 library that is much faster than the earlier version.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dirigo

Thanks Hutch for your response.

I was just racing here to post to save you some keystrokes, but ... failed you!

Yes, after doing a lot of poking here and there and reading a few posts in regards to inkey and wait_key macros, etc., I decided my approach of trying to put square pegs into round holes wasn't going to work ... very smoothly, that is.  ::)  Soooo, I had just done what you suggested in terms of downloading the most current version (masm32 Version 9.0), installed it, assembled your demo program and ... all went well ... as the Colonel on The A-Team used to utter "I love it when a plan comes together!".

Thanks again.  I really do appreciate yours and others efforts here.