; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ; klib.asm ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ; Forrest Yu, 2005 ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %include "sconst.inc" ; 导入全局变量 extern disp_pos [SECTION .text] ; 导出函数 global disp_str global disp_color_str global write_char ; added by mingxuan 2019-5-19 ; ======================================================================== ; void disp_str(char * info); ; ======================================================================== disp_str: push ebp mov ebp, esp pushad mov esi, [ebp + 8] ; pszInfo mov edi, [disp_pos] mov ah, 0Fh .1: lodsb test al, al jz .2 cmp al, 0Ah ; 是回车吗? jnz .3 push eax mov eax, edi mov bl, 160 div bl and eax, 0FFh inc eax mov bl, 160 mul bl mov edi, eax pop eax jmp .1 .3: ;added by xw, 17/12/11 ;added begin cmp edi, 1F40h jnz .4 mov edi, 0FA0h .4: ;added end mov [gs:edi], ax add edi, 2 jmp .1 .2: mov [disp_pos], edi popad pop ebp ret ; ======================================================================== ; void disp_color_str(char * info, int color); ; ======================================================================== disp_color_str: push ebp mov ebp, esp pushad mov esi, [ebp + 8] ; pszInfo mov edi, [disp_pos] mov ah, [ebp + 12] ; color .1: lodsb test al, al jz .2 cmp al, 0Ah ; 是回车吗? jnz .3 push eax mov eax, edi mov bl, 160 div bl and eax, 0FFh inc eax mov bl, 160 mul bl mov edi, eax pop eax jmp .1 .3: mov [gs:edi], ax add edi, 2 jmp .1 .2: mov [disp_pos], edi popad pop ebp ret ; ======================================================================== ; void write_char(char ch); ; ======================================================================== write_char: push ebp mov ebp,esp mov esi,[ebp+8] mov edi,[disp_pos] push eax mov eax,esi mov ah, 0Fh mov [gs:edi], ax pop eax pop ebp ret