Printing a string without OS

落爺英雄遲暮 提交于 2019-11-27 08:06:35

问题


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 0x10
sdl
mov ax, 0xb800
mov es,ax
mov si, msg
xor di, di
repnz movsw
jmp $
msg db 'Hello'
times 510 - ($ - $$) db 0
dw 0xaa55

But it doesn't work. Can you help me?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/15462807/printing-a-string-without-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!