1 00:00:00,180 --> 00:00:07,050 There is one more thing we need to do before we switch to long mode, which is set video mode. 2 00:00:07,050 --> 00:00:11,040 Printing on the screen is done by the bios service in real mode. 3 00:00:12,130 --> 00:00:18,180 Once we switch to long mode, we are unable to call bios function. So we set up a video mode 4 00:00:18,190 --> 00:00:19,840 and print characters on that mode. 5 00:00:20,820 --> 00:00:27,300 There are a lot of video mode we can use. Our system choose text mode in which printing characters is really simple 6 00:00:27,300 --> 00:00:27,770 . 7 00:00:28,290 --> 00:00:31,970 All we need to do is specify the ascii code for the character we want to print 8 00:00:31,980 --> 00:00:38,920 and the attribute for that character such as foreground color and background color. computer. 9 00:00:39,900 --> 00:00:43,950 We write them on the specific address and the data will appear on the screen. 10 00:00:45,740 --> 00:00:48,380 OK, let's see how to set up text mode. 11 00:00:56,460 --> 00:00:59,200 To set up text mode, we use interrupt 10 12 00:01:04,930 --> 00:01:11,020 and function code 0 in ah register which means we want to set video mode. 13 00:01:11,020 --> 00:01:17,260 Then we need to choose video mode, text mode in this case, by copying 3 to al register. 14 00:01:19,560 --> 00:01:20,730 So we copy 15 00:01:22,400 --> 00:01:24,740 3 to ax to set it up. 16 00:01:26,450 --> 00:01:32,870 Ok now we have set up text mode and we can print message on screen without calling BIOS service. 17 00:01:34,080 --> 00:01:35,790 Let’s see how to print characters. 18 00:01:36,930 --> 00:01:38,490 Remove the print function. 19 00:01:40,820 --> 00:01:49,070 The base address for text mode is b8000. The size of screen we can print on is 80*25 20 00:01:49,070 --> 00:01:49,930 . 21 00:01:50,660 --> 00:01:54,730 So we have 25 lines and we can print 80 characters each line. 22 00:01:55,430 --> 00:01:58,160 Every character takes up 2 bytes of space. 23 00:01:58,730 --> 00:02:04,220 The first position on the screen corresponds to the two bytes at b8000. 24 00:02:05,060 --> 00:02:11,360 The second position corresponds to the two bytes at b8002, and so on. 25 00:02:12,570 --> 00:02:19,920 Within the 2 bytes of memory space, the first byte is for ascii code and the second byte is 26 00:02:19,930 --> 00:02:20,790 attribute of the character. 27 00:02:22,100 --> 00:02:29,740 The lower half are foreground color and the higher half are background color. The color index is listed here. 28 00:02:30,410 --> 00:02:33,200 For example, we print text mode is set. 29 00:02:34,420 --> 00:02:37,150 We change the message to text mode is set. 30 00:02:43,030 --> 00:02:43,760 we move 31 00:02:45,440 --> 00:02:47,150 si message 32 00:02:50,180 --> 00:02:51,200 and di 33 00:02:53,280 --> 00:03:01,920 0xb8000. What we do here is save the address of characters to regiser si and text mode address 34 00:03:02,610 --> 00:03:04,200 b8000 to di. 35 00:03:05,160 --> 00:03:10,450 Note that the value b8000 is too large for 16-bit register di to store. 36 00:03:11,190 --> 00:03:13,650 So we save b800 to 37 00:03:17,970 --> 00:03:18,990 es register 38 00:03:22,130 --> 00:03:23,840 and zero di register. 39 00:03:28,480 --> 00:03:34,720 When we reference the memory address b8000, we use es di which points to the same memory location 40 00:03:34,720 --> 00:03:35,350 . 41 00:03:36,950 --> 00:03:40,010 We also save the number of characters to cx. 42 00:03:44,610 --> 00:03:46,980 Then we print characters one at a time. 43 00:03:51,460 --> 00:03:53,230 move al si 44 00:03:57,270 --> 00:03:59,640 and move es di, 45 00:04:02,370 --> 00:04:02,860 al. 46 00:04:04,360 --> 00:04:10,420 We copy the data in memory pointed to by si which is the first character of message at this point. 47 00:04:10,870 --> 00:04:19,029 and copy the data to the memory addressed by di which is b8000. Next we specify 48 00:04:19,029 --> 00:04:20,890 the attribute of character in the next byte, 49 00:04:22,250 --> 00:04:25,910 we use color index a which is bright green. 50 00:04:30,510 --> 00:04:34,140 Ok now we have printed the first character in green. 51 00:04:35,140 --> 00:04:39,130 We continue the same process until all the characters have been printed. 52 00:04:40,680 --> 00:04:50,580 So we add di,2 and si 1. Because the character takes up two bytes and 53 00:04:50,580 --> 00:04:52,560 the character stored in message takes up 1 byte. 54 00:04:54,260 --> 00:05:01,220 By adjusting di and si register, we just move to the next character. The last instruction is loop 55 00:05:01,220 --> 00:05:07,760 which use cx register as a counter so that we can continue the process. 56 00:05:10,110 --> 00:05:15,960 As you see, we have initialized the cx with the number of characters. So loop instruction will execute 57 00:05:15,960 --> 00:05:18,300 this block of code the same number of times. 58 00:05:19,690 --> 00:05:21,730 OK, let's build the project. 59 00:05:28,090 --> 00:05:29,350 and the run the bochs. 60 00:05:32,740 --> 00:05:36,430 As you see, we printed a message without using bios service. 61 00:05:38,410 --> 00:05:45,700 This is a message we have printed in the real machine and in the next video, we will switch to protected mode 62 00:05:45,700 --> 00:05:45,980 . 63 00:05:46,330 --> 00:05:47,590 See you in the next video.