HLA programming I am trying to modify the code below from 16-bit short packed da
ID: 3752298 • Letter: H
Question
HLA programming
I am trying to modify the code below from 16-bit short packed date format to 32-bit, long packed date format, which i assume I will have to envolve "eax" the register.
The code below intakes an input of a date in the format (MM, DD, YY) and outpiut the hexadecimal format which can be managed by a 16-bit packed data. But we are required to intake an input of a date in the format (YYYY, MM, DD) and pref orm the same function but this requires more than 16 bit so we are supposed to use a 32 bit pakage which will require us to invlove eax for an additional 16 bit of storage. (i.e. Input: March 26, 1948. (input: 1948, 3, 26), Output will be 079C031A)
program dateDemo;
#include( "stdlib.hhf" )
static
day: uns8;
month: uns8;
year: uns8;
packedDate: word;
begin dateDemo;
stdout.put( "Enter the current month, day, and year: " );
stdin.get( month, day, year );
// Pack the data into the following bits:
//
// 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// m m m m d d d d d y y y y y y y
mov( 0, ax );
mov( ax, packedDate ); // Just in case there is an error.
if( month > 12 ) then
stdout.put( "Month value is too large", nl );
elseif( month = 0 ) then
stdout.put( "Month value must be in the range 1..12", nl );
elseif( day > 31 ) then
stdout.put( "Day value is too large", nl );
elseif( day = 0 ) then
stdout.put( "Day value must be in the range 1..31", nl );
elseif( year > 99 ) then
stdout.put( "Year value must be in the range 0..99", nl );
else
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 ); // Retrieve the month value.
rol( 4, ax );
and( %1111, al );
mov( al, month );
stdout.put( "The date is ", month, "/", day, "/", year, nl );
end dateDemo;
Explanation / Answer
#include #include #include int main(void) { time_t current_time; char* c_time_string; /* Obtain current time. */ current_time = time(NULL); if (current_time == ((time_t)-1)) { (void) fprintf(stderr, "Failure to obtain the current time. "); exit(EXIT_FAILURE); } /* Convert to local time format. */ c_time_string = ctime(¤t_time); if (c_time_string == NULL) { (void) fprintf(stderr, "Failure to convert the current time. "); exit(EXIT_FAILURE); } /* Print to stdout. ctime() has already added a terminating newline character. */ (void) printf("Current time is %s", c_time_string); exit(EXIT_SUCCESS); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.