1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Melbourne, Australia
    Rep Power

    ASM: printing out HEX value


    I have a HEX value stored - how do I print out this HEX value? If I just try to print it out, it prints out the ASCII equivalent (ie 4D prints M but I want it to just print 4D).

    It's for the Motorola 68000 processor if that matters.

  2. #2
  3. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Alpharetta, GA
    Rep Power
    This is a fairly common problem, actually. This post covers the general algorithms for binary to ASCII and ASCII to binary conversions; the code is written in Python, but it should be fairly easy to convert it to any language you choose, including M68k assembly.

    It should be pointed out that the value you have is a binary value, not a hex value, even though it may have been written in hex in the assembly code or read in as a hex value. What you actually want to do is convert the binary value into a string holding it's hex representation in ASCII text. Keep in mind as well that, depending on how you handle printing the hex value, you will probably need a string buffer large enough to hold the string; for hex values, you need two bytes of characters for each binary byte.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

IMN logo majestic logo threadwatch logo seochat tools logo