2

我只会写汇编代码。

我想使用中断 10h/13h 将字符串写入屏幕。但我不知道如何使用 turbo pascal 中的程序集定义或保存在内存中的字符串。

这没有用:

msg1 'hello, world!$'

我的代码:

program string;

begin
asm
    mov ah,$0
    mov al,03h
    int 10h;

    mov ax,1300h
    mov bh,$0
    mov bl,07h
    mov cx,$9
    mov dl,$0
    mov dh,$0
    int 10h

    mov ah,00h
    int 16h 

end;
end.

有人知道吗?

4

1 回答 1

3

后缀“$”作为终止字符仅适用于某些 DOS 功能。INT 10h / AH=13h(Video-BIOS 函数)处理CX. “Pascal-string”的长度在第一个字节中。它没有像 DOS-/C-/ASCIIZ 字符串那样的终止字符。您可以从这里获得 TP 手册——尤其是程序员指南。

看这个例子:

program string_out;

var s1 : string;

procedure write_local_string;
var s3 : string;
begin
    s3 := 'Hello world from stack segment.';
    asm
        push bp                 { `BP` is in need of the procedure return }
        mov ax, ss
        mov es, ax
        lea bp, s3              { Determine the offset of the string at runtime }
        mov ax, 1300h
        mov bx, 0007h
        xor cx, cx              { Clear at least `CX` }
        mov cl, [es:bp]         { Length of string is in 1st byte of string }
        inc bp                  { The string begins a byte later }
        mov dx, 0200h           { Write at third row , first column}
        int 10h
        pop bp
    end;
end;

begin
    s1 := 'Hello world from data segment.';
    asm
        mov ah, 0
        mov al, 03h
        int 10h;

        mov ax, ds
        mov es, ax
        mov bp, offset s1
        mov ax, 1300h
        mov bx, 0007h
        xor cx, cx              { Clear at least `CH` }
        mov cl, [es:bp]         { Length of string is in 1st byte of string }
        inc bp                  { The string begins a byte later }
        mov dx, 0000h           { Write at first row , first column}
        int 10h

        mov ax, cs
        mov es, ax
        mov bp, offset @s2
        mov ax, 1300h
        mov bx, 0007h
        mov cx, 30              { Length of string }
        mov dx, 0100h           { Write at second row , first column}
        int 10h

        jmp @skip_data
        @s2: db 'Hello world from code segment.'
        @skip_data:
    end;

    write_local_string;
    writeln; writeln;           { Adjust cursor }
end.
于 2015-04-26T08:33:22.413 回答