News:

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

I'm stuck in this code

Started by Xor Stance, July 16, 2005, 01:02:21 AM

Previous topic - Next topic

Xor Stance

Definitely I know what the operands as the example tells it. But this one
I definitely don't know how is it going? Can someone describe each of
this piece of code and what it does to be able to input the values.
I had watch the calculator but I'm not machine expert or understand
some of it.

      
        mov( month, al );

        shl( 5, ax );

        or( day, al );

        shl( 7, ax );

        or( year, al );

        mov( ax, packedDate );



    endif;

   

    // Okay, display the packed value:

   

    stdout.put( "Packed data = $", packedDate, nl );

   

   

   

    // Unpack the date:



    mov( packedDate, ax );

    and( $7f, al );         // Retrieve the year value.

    mov( al, year );

   

    mov( packedDate, ax );  // Retrieve the day value.

    shr( 7, ax );

    and( %1_1111, al );

    mov( al, day );

   

    mov( packedDate, ax );  // Retrive the month value.

    rol( 4, ax );

    and( %1111, al );

    mov( al, month );

I somehow understand the hexadecimal 127 it's multiply but don't know what happened
to the AL register.

Sevag.K

Okay, to help you understand what's going on here, I'll offer an interactive tutorial.

1. Download the "cCalc" program I uploaded to the "two's compliment notation" thread (if you don't already have it).

2. Now, to see how the data is being packed, run cCalc.

3. click on the edit box labeled "Op", type in todays month, and click on the "OR" button.

4. clik on the "SHL" button 5 times.  This is the same as: shl (5, ax); in your code.

5. back to the "Op" edit box, type in today's day, and click on the "OR" button.
This represents the: or (day, al);  in your code.

6. click on the "SHL" button 7 times.  This represents shl(7, ax); in your code.

7. finally, back to the "Op" edit box, type in the 2 digit representation of this year, then
click the "OR" button.

All this time, see what's happening in the bits boxes on the top.  This is how your data
is getting packed.

I'll leave the unpacking part as an exercise.  cCalc will be able to assist you here as well.
If you need more help, let me know.



Xor Stance