print string with bios interrupt 0x10

拈花ヽ惹草 提交于 2021-02-08 07:10:33

问题


I want to print a string using bios interrupt 0x10. But I get only a blue fiel, without letters in it. Maybe I habe a problem by adressing my string.

Edit: I have two code files. The first is written on the first sector of a floppy. It copys the second sector from the floppy to the memory (starting at 0x5000) and jump to 0x5000. Here is my second file, where I should print my string.

[BITS 16]
org 0x5000

sect2:
    mov ah, 0x03    ;get curser position
    mov bh, 0x00    ;page number

    int 0x10

    mov ax, 0x0500 
    mov es, ax
    mov bp, bsy1msg 

    mov ah, 0x13            ;write string
    mov al, 0x01            ;update cursor after writing
    mov bh, 0x00            ;page number
    mov bl, 0x1F            ;atributes
    mov cx, bsy1len         ;number of characters in string

    int 0x10

end:
    jmp end

bsy1msg db 13,10,"BSY1 via INT 0x10"
bsylen equ $ - bsy1msg

回答1:


The org directive doesn't cause the program to be loaded at a specific physical address, it informs the assembler to assume that the program is loaded that far into the code segment.

So for example, the value of sect2 is not zero, it's 0x5000.

Setting es to 0x500 would make it start at the physical address 05000, but that's not where the program is. You want the extra segment to start at the same point as the code segment, as the bsy1msg label is relative to the code segment (and has the value 0x501d if I calculated correctly).

push cs
pop es



回答2:


An address is expressed as segment:offset, and the physical address is calculated as segment*16+offset. So 0x0500:0 refers to the same physical address as 0:0x5000. If your program is located at the physical address 0x5000 then CS:IP should be 0x0500:0 or 0:0x5000. The string is located at the physical address 0x501d. Since you specify org 0x5000 nasm will assume the offset of bsy1msg to be 0x501d. Which means that the segment has to be 0 (0*16+0x501d = 0x501d). Or, if you set ES to 0x0500 (directly or by copying CS), you need to either omit org 0x5000 or subtract the offset from BP (mov bp,bsy1msg-sect2) to get the right physical address (0x0500*16+0x001d = 0x501d).



来源:https://stackoverflow.com/questions/27332266/print-string-with-bios-interrupt-0x10

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