I am learning about packing data with assembly language (specifically HLA), which is a simple enough concept. However, in the following demo proram (shortened from the actual version), I don’t understand why 0 is moved into ax?
static
day: uns8;
month: uns8;
year: uns8;
packedDate: word;
begin test1;
stdout.put( "Enter the current month, day, and year: " );
stdin.get( month, day, year );
mov( 0, ax );
mov( ax, packedDate ); // Just in case there is an error.
mov( month, al );
shl( 5, ax );
or( day, al );
shl( 7, ax );
or( year, al );
mov( ax, packedDate );
// 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 ); // Retrieve the month value.
rol( 4, ax );
and( %1111, al );
mov( al, month );
stdout.put( "The date is ",month, "/", day, "/",year, nl );
end test1;
Removing that line did not seem to have any effect. What is the purpose of moving 0 into ax, and then ax into packedDate?
Platform is Win764
Moving 0 into
packedDatedoesn’t do anything here as you have notices, but I’m guessing it was done to make the code easier to extend with error checks. At present the code doesn’t check for invalid dates, if the code was modified to do that apackedDateof 0 would signify an invalid date.Moving 0 into
axis on the other hand required to clear the 8 most significant bits (ah) before the following code is executed:If
ahwasn’t clear you could still have junk bits left over from previous operations. The code could also have been written as: