Function 13h, which arrived with the PC/AT and the EGA, is teletype for a whole string with colours. It puts the cursor of page BH at row DH, column DL, writes CX characters from ES:BP, and acts on CR, LF, backspace and bell as function 0Eh does, scrolling at the bottom. The write mode in AL decides two things:
| AL | The string | The cursor afterwards |
|---|---|---|
| 00h | characters, all in attribute BL | back where it was |
| 01h | characters, all in attribute BL | after the string |
| 02h | character, attribute, character, attribute... | back where it was |
| 03h | character, attribute pairs | after the string |
The string is addressed by ES:BP, not DS:DX or DS:SI as one might expect. In a .COM program ES already equals DS, so MOV BP, OFFSET TEXT1 is all it takes; an .EXE must set ES first. CX counts characters, so in modes 02h and 03h the string is 2 × CX bytes long, and no terminator is needed or recognised.
MOV AH, 03h ; start at the cursor: DH = row, DL = columnMOV BH, 0INT 10hMOV AX, 1301h ; write a string: one attribute, move the cursorMOV BX, 001Eh ; page 0, yellow on blueMOV CX, 16 ; 14 characters, then CR and LFMOV BP, OFFSET TXT1 ; ES:BP = the string (ES = DS in a .COM)INT 10hMOV AH, 03h ; the cursor is now on the next lineMOV BH, 0INT 10hMOV AX, 1303h ; character, attribute pairs; move the cursorMOV BX, 0000h ; page 0 (BL is not used)MOV CX, 5 ; 5 characters: CX does not count the attributesMOV BP, OFFSET TXT2INT 10hMOV AH, 09hMOV DX, OFFSET MSG1INT 21hTXT1 DB "Yellow on blue", 13, 10TXT2 DB "R", 0Ch, "G", 0Ah, "B", 09h, 13, 07h, 10, 07hMSG1 DB "Two lines above from INT 10h AH=13h", 13, 10, "$"
Pitfalls
BP holds the string pointer, so code that keeps a stack frame in BP must save it around the call. The original PC and XT BIOS lack the function and return without doing anything. The cursor position comes from DH and DL, not from the current cursor, so to write "at the cursor" read it first with function 03h, as the example does. In modes 00h and 01h a CR or LF in the string moves the cursor without being drawn, and the attribute applies only to the characters drawn.