Author Topic: how dose byte to string really works  (Read 10827 times)

Offline HELLFIX

  • Jr. Member
  • *
  • Posts: 6
how dose byte to string really works
« on: May 04, 2012, 04:41:06 PM »
why do you need to mask the upper 12 bits


and     DI, 000Fh  ;Mask out the unwanted
                   ;high 12 bits by setting
                   ;them to 0 leaving the
                   ;low 8 bits conserved as
                   ;been copied from AX,
                   ;lets say we copied 0ABh
                   ;to AL this instruction
                   ;will make DI look like
                   ;this: DI=000B;

i want to know why exactly do you need to do this
which part of the example code its it converting bytes to string

and  is there a simpler way
to convert byte to string

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: how dose byte to string really works
« Reply #1 on: May 05, 2012, 01:56:12 AM »
I suppose you're looking at Shikatsu's example?

http://forum.nasm.us/index.php?topic=1335.0

In any case, we probably want a 16-bit register so we can add it to another 16-bit register, but we only want the value of a single digit. The comment you show isn't quite correct - only four bits remain in the result, not eight.

There's a "logical" or "boolean" and, in which the result is "true" (non-zero) if both operands are "true" - "false" (zero) is either or both are "false". The "and" instruction works on a bitwise basis - a bit in the result is 1 if the corresponding bits in both operands are 1, the bit is 0 if either or both bits are zero. In this case, the result has a numeric value, not just "true" or "false".

There are a number of ways to convert byte (or larger value) to a string... and the number can be represented as decimal or hex... or other. "Just call printf" is pretty simple - the code to printf isn't simple, but someone else wrote it! :)

Maybe if you tell us more about what you're trying to do, or exactly which code you're looking at, we can be more help. Wait'll you see floating point! :)

Best,
Frank


Offline HELLFIX

  • Jr. Member
  • *
  • Posts: 6
Re: how dose byte to string really works
« Reply #2 on: May 05, 2012, 08:04:29 PM »
oh ok i see what you mean i want to know how to convert a byte to string so i can print it on to the screen. i dont know how to include printf if in nasm
i tried masm but it does not work eithers so im sticking with nasm for assembly programming

Offline HELLFIX

  • Jr. Member
  • *
  • Posts: 6
Re: how dose byte to string really works
« Reply #3 on: May 07, 2012, 12:22:07 AM »
Thanks again frank i understand how to convert byte to string using the sample code