2017-12-15 5 views
2

나는 흰색 전경과 파란색 배경을 가진 문자열을 출력하기 위해 노력하고있어 :색상 화 조립 출력

[BITS 16]        ;16 bit code 
[ORG 0x7C00]       ;Origin location 

SECTION .DATA       ;Data section 
    output: db 'Hello World', 10, 0  ;Output string (10 = \n, 0 = \0) 

;Entry point 
main:         
    mov ax, 0x0000      ;Initialize the ds register 
    mov ds, ax       ;ds isn't a general purpose register => value has to be copied 

    mov si, output      ;Load the string into the si register 
    call printString     ;Call the printString function 

    jmp $        ;Endless loop 

;Prints output 
printString:  
    mov ah, 0x0E      ;Function 0x0E = Display character 
    mov bh, 0x00      ;Set the page number to zero 
    mov bl, 0x1F      ;Set the text attribute (0x1F = Blue bg, White fg) 
    jmp printChar      ;Jmp to printChar (just for code eroticism) 

;Prints every char from output until 0 
printChar:        ;Jmp point to loop through the string 
    lodsb        ;Load the byte at si into al 
    or al, al       ;Sets the zero flag if al = 0 
    jz return       ;Return if the end of the string is reached 

    int 0x10       ;Call the bios video service 
    jmp printChar      ;Continue to print the string 

;Returns to main 
return:         ;Jmp point to return 
    ret         ;Return to main 

times 510-($-$$) db 0     ;Fill the rest of the floppy with zeros 
dw 0xAA55        ;Boot loader signature 

그것은 인쇄에 "Hello World"를 다음 행으로 이동하지만, 항상 검은 색에 회색이다. mov bl, 0x1Fint 0x10을 색칠하지 않아야합니까?

편집

사람이 같은 문제가있는 경우 : 나는 색상을 변경하려면이 기능을 추가하고 텍스트 속성 행을 제거하십시오 int 10h BIOS 루틴의

setColors: 
    mov ah, 0x06 ;Function 0x06 = Scroll up function 
    xor cx, cx  ;From upper left corner 
    mov dx, 0x184F ;To lower right corner 
    mov bh, 0x1F ;Set colors (white on blue) 
    int 10H   ;Call the bios video interrupt 
    ret    ;Return 
+1

당신은 단순히 자신의 출력 루틴을 생성하지 않는 이유는 어떤 특별한 이유 (전체 콘솔 API, 당신은 OS, 또는 부트 로더에 대한 단순한 "인쇄"헬퍼를 작성하는 경우) 서면으로 느린 BIOS를 완전히 무시한'B800 : 0000'? – Ped7g

+0

간단히 말해서 나는 현재 어셈블리를 배우고 있기 때문에 단순히 아래에서 위로 가고 싶었습니다. – 91378246

+1

아주 잘 보입니다. (아주 기본적인 것은 DOS 에뮬레이션을 사용하고 COM 파일을 먼저 만들고, 부트 로더 코드와 여러면에서 유사하지만 DOS는 더 많이 사용합니다. 용서할 수있는 환경, 특히 모든 종류의 다양한 버크와 ​​준비되지 않은 부트 로더로 부팅하는 경향이있는 실제 HW BIOS와 비교할 때 환경이 좋습니다. 그래서 만약 당신이 지금'int 0x10'을 마스터했다면 직접 ['B800 : 0000' 메모리 액세스] (http://www.shikadi.net/moddingwiki/B800_Text)를 들여다 볼 수 있습니다. + 나중에 VGA를 추가하십시오 컨트롤 regs, 재미 있어야/재미 :) – Ped7g

답변