solution

change this c code to assembly. gcc 86×64

like this.

cmpl $86400, %edi

jge .OOB

cmpl $0, %edi

jl .OOB

—-

#include “clock.h”

clock.h “

typedef struct{

short hours;

short minutes;

short seconds;

char ampm; // 1 for am, 2 for pm

} tod_t;

// size in bits of some types

//#define INT_BITS (sizeof(int)*8)

//define blank and Negative value

//#define Negative 0b1000000

//define Blank 0b0000000

// set digits

int count = 0;

int set_tod_from_secs(int time_of_day_sec, tod_t *tod)

{

if(time_of_day_sec < 0 || time_of_day_sec >= 86400)

{

return 1;

}

int tod_hours = time_of_day_sec /3600;

int tod_minutes =(time_of_day_sec/ 60) % 60;

int tod_seconds =time_of_day_sec %60;

//int ampm =(tod_hours >= 12 )?2 : 1;

//if the a is treu, evaluate b otherwise c.

int ampm;

if(tod_hours >=12)

{

ampm= 2;

}

else

{

ampm = 1;

}

tod_hours =tod_hours %12;

//tod_hours = tod_hours == 0 ?12 :tod_hours;

if (tod_hours == 0)

{

tod_hours = 12;

}

else{

tod_hours = tod_hours;

}

tod->ampm = ampm;

tod->hours = tod_hours;

tod->minutes = tod_minutes;

tod->seconds = tod_seconds;

return 0;

}

// int set_display_from_tod(tod_t tod, int *display);

int set_display_from_tod(tod_t tod, int *display)

{

int Am = 0x1 << 28;

int Pm = 0x1 << 29;

if(tod.hours < 0 || tod.hours > 12)

{

return 1;

}

else if(tod.minutes < 0 || tod.minutes > 59)

{

return 1;

}

else if(tod.seconds < 0 || tod.seconds > 59)

{

return 1;

}

else if (tod.ampm != 1 && tod.ampm != 2)

{

return 1;

}

// Create an array of bit masks for each of the digits 0-9

//the array contains a bit mask

//zero = 0b0111111

//one = 0b0110000

//two = 0b1101101

//three= 0b1111001

//four = 0b1110010

//five = 0b1011011

//six = 0b1011111

//seven= 0b0110001

//eight= 0b1111111

//nine = 0b1111011

int mask[10] =

{ 0b0111111, 0b0110000, 0b1101101, 0b1111001, 0b1110010, 0b1011011, 0b1011111, 0b0110001, 0b1111111, 0b1111011,};

int min_tens_hour = 0b0000000;

int min_ones_hour = mask[tod.hours % 10];

int min_tens_minutes = mask[tod.minutes / 10];

int min_ones_minutes = mask[tod.minutes % 10];

int ampm = 0;

if(tod.hours >= 10)

{

min_tens_hour = mask[1];

}

if(tod.ampm == 2)

{

ampm = Pm;

}

else if (tod.ampm ==1)

{

ampm = Am;

}

count |= ampm;

// Bits 0-6 control the ones place of the minutes

// Bits 7-13 control the tens place of the minutes

// Bits 14-20 control the ones place of the hours

// Bits 21-27 control the tens place of the hours

count |= (min_ones_minutes << 0);

count |= (min_tens_minutes << 7);

count |= (min_ones_hour << 14);

count |= (min_tens_hour << 21);

*display = count;

return 0;

}

int clock_update()

{

tod_t tod;

if(set_tod_from_secs(TIME_OF_DAY_SEC, &tod) != 0 || set_display_from_tod(tod, &count) != 0)

{

return 1;

}

CLOCK_DISPLAY_PORT = count;

return 0;

}

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp