2

I've read the Intel manuals but I don't understand most part of it. I am trying to convert a Quadword (64-bit) decimal to string by using two 32-bit registers.

mov eax,dword[value+4]
mov ecx,dword[value]
shld eax,ecx,1  *;This translates to what?*
...
value dq 45678910123457

What do I get in the end? Can I separate digits (to be translated to ASCII later on) this way? How?

EDIT: Ok, to be more specific - for dword integer (base 10), I can separate the digits by using multiple DIVs. But for a quadword data, it is not possible to use DIV. I think SHLD, in part, can do the job but I just have no idea how it works.

royalfinest
  • 155
  • 1
  • 8
  • You'd get `eax = 21270` (I think). As usual, the result of a bitwise operation is not very clear when looked at in decimal. I don't see what this has to do with decimal (right?) digits. – harold Oct 02 '14 at 15:07
  • I suggest you use hexadecimal instead of decimal to better "see" binary operations. – m0skit0 Oct 02 '14 at 15:14
  • Thanks harold. I've read from somewhere (I just can't recall where) that for a larger data, I can use SHLD to separate the digits into ASCII. My problem now is how to even begin using SHLD. – royalfinest Oct 02 '14 at 15:20
  • 4
    IDIV takes a 64-bit dividend, stored in EDX:EAX. SHLD is a hammer that doesn't strike any nails here. – Hans Passant Oct 02 '14 at 15:23
  • @ mOskit0 - I already completed the hex and binary codes. No problem there. Translates just as natural. The only problem now is translating base-10 to ascii for a quadword data. – royalfinest Oct 02 '14 at 15:24
  • [paxdiablo's answer to an earlier SO question](http://stackoverflow.com/questions/9975848/is-this-code-correct-number-plus-number-then-print-the-result/9975882#9975882) has pseudocode and 16-bit DOS x86 code for decimal printing. You should be able to get the idea from the pseudocode or 16-bit code. – nrz Oct 02 '14 at 18:39

1 Answers1

1
SHLD/SHRD - Double Precision Shift (386+)

        Usage:  SHLD    dest,src,count
                SHRD    dest,src,count
        Modifies flags: CF PF SF ZF (OF,AF undefined)

        SHLD shifts dest to the left count times and the bit positions
        opened are filled with the most significant bits of src.  SHRD
        shifts dest to the right count times and the bit positions
        opened are filled with the least significant bits of the second
        operand.  Only the 5 lower bits of count are used.

wow a simple google and the answer is crystal clear...

As far as what should you expect to see with the number you chose, it is too big for my calculator to convert it to hex so i cant help you there, but if you really want to know then why not just type this code in (cut and paste) and run it and print out the answer? What did you get when you tried that?

these are for binary not decimal, you use these to right or left shift (multiply or divide by powers of 2) for values that wont fit in a single register.

Computers are not base 10 the very very old base 10 instructions (BCD) are simply not used anymore, we programmers have not thought in base 10 for decades. These have no use for anything base 10.

old_timer
  • 69,149
  • 8
  • 89
  • 168