Page 1 of 1
Showing Time in boot sector
Posted: Mon Nov 30, 2015 7:08 am
by Haghiri75
Greetings.
As a project, I wrote a 16bit-real mode boot sector using NASM, and then I showed it to my teacher. He asked me for adding "Showing time" feature.
What I used is :
But, this only "returns" time and doesn't show it. What can I do for showing it?
Re: Showing Time in boot sector
Posted: Mon Nov 30, 2015 7:48 am
by Octocontrabass
Since that function returns the time in ticks since midnight, you'll have to do some math to convert it to hours:minutes:seconds before you can display it. You should take a look at int 0x1a ah=0x02 and see if that might be closer to what you want.
Once you have the time, you must convert it to ASCII to display it. First, separate the tens and ones digit. For numbers between 0 and 99, you can divide by 10; the quotient is the tens digit and the remainder is the ones digit. For BCD, the top four bits of the byte are the tens digit and the bottom four bits are the ones digit; you can separate those with some bit manipulation. After you've got them separated, add 0x30 to get the ASCII character value for that digit. You can display the ASCII characters on the screen using one of the int 0x10 functions, such as int 0x10 ah=0x0e.
Re: Showing Time in boot sector
Posted: Mon Nov 30, 2015 8:39 am
by intx13
To expand on Octocontrabass's answer, assuming that you decide to use INT1A, AH=02, you will receive the time as below:
CH = hour (BCD)
CL = minutes (BCD)
DH = seconds (BCD)
Wikipedia has an article on BCD, if you're not familiar with it. To extract each digit in the hour (for example), you'd want to separate the lower and upper 4 bits like this:
Code: Select all
hour_1s_digit = hour_bcd & 0x0F // hour_1s_digit holds the 1's digit (i.e. 12 -> 2)
hour_10s_digit = hour_bcd >> 4 // hour_10s_digit holds the 10's digit (i.e. 11 -> 1)
To convert each digit to ASCII, refer to
this table and add the offset for '0', like this:
Code: Select all
hour_1s_char = hours_1s_digit + 0x30 // hour_1s_char holds the 1's digit character (i.e. 2 -> '2')
hour_10s_char = hours_10s_digit + 0x30 // hour_10s_char holds the 10's digit character (i.e. 1 -> '1')
Now you can print out each character with INT10H, AH=0E.