Showing Time in boot sector

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Haghiri75
Member
Member
Posts: 29
Joined: Fri Nov 16, 2012 4:16 am
Location: Iran
Contact:

Showing Time in boot sector

Post 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 :

Code: Select all

mov ah,0
 int 0x1a
But, this only "returns" time and doesn't show it. What can I do for showing it?
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: Showing Time in boot sector

Post 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.
intx13
Member
Member
Posts: 112
Joined: Wed Sep 07, 2011 3:34 pm

Re: Showing Time in boot sector

Post 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.
Post Reply