The MASM Forum Archive 2004 to 2012

Project Support Forums => HLA Forum => Topic started by: Xor Stance on July 16, 2005, 01:02:21 AM

Title: I'm stuck in this code
Post by: Xor Stance on July 16, 2005, 01:02:21 AM
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.
Title: Re: I'm stuck in this code
Post by: Sevag.K on July 16, 2005, 02:45:22 AM
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.


Title: Re: I'm stuck in this code
Post by: Xor Stance on July 16, 2005, 04:23:11 AM
Thank you very much!