Printing a string without OS

前端 未结 2 1111
长情又很酷
长情又很酷 2020-12-11 20:52

I have a simple program in x86 assembly language. It should print a string directly to the video memory without OS.

[bits 16]
[org 0x7c00]
mov ax, 0x3
int 0x         


        
相关标签:
2条回答
  • 2020-12-11 21:14

    With the repnz prefix you must first set the cx register to the character count, and as nrz points out you shouldn't use that one as it stops when zero is encountered.

    0 讨论(0)
  • 2020-12-11 21:20

    There are some issues:

    1. There is no such instruction as sdl.

    2. To copy data, you should use rep movsw, not repnz movsw.

    3. You need to set cx before rep movsw.

    4. You need to define the colors of each character too, in every other byte of video memory, either in the data to be copied with rep movsw, or inside copy loop. The code below illustrates both options:

    Edit: added code.

    [bits 16]
    [org 0x7c00]
    
    mov ax,3
    int 10h
    
    push word 0xb800
    pop  es
    
    push cs    ; just in case, for bootloader code,
    pop  ds    ; needed for movsb 
    
    xor di,di
    mov si,msg
    mov cx,msg_length_in_bytes
    
    one_color_copy_to_vram_loop:
        movsb
        mov al,0x0f
        stosb
        loop one_color_copy_to_vram_loop
    
    mov si,multicolor_msg
    mov cx,multicolor_msg_length
    rep movsw
    
    jmp $
    
    msg db 'Hello'
    msg_length_in_bytes equ $-msg
    
    multicolor_msg db ' ',0
                   db 'H',1
                   db 'e',2
                   db 'l',3
                   db 'l',4
                   db 'o',5
                   db ' ',0 
                   db 'w',6
                   db 'i',7
                   db 't',8
                   db 'h',9
                   db ' ',0
                   db 'c',10
                   db 'o',11
                   db 'l',12
                   db 'o',13
                   db 'r',14
                   db '!',15
    multicolor_msg_length equ ($-multicolor_msg)/2
    
    0 讨论(0)
提交回复
热议问题