2

I only can write assembly code.

I want to use the interruption 10h/13h to write a string to the screen. But I can't figure out how to define or save in memory a string using assembly in turbo pascal.

This didn't work:

msg1 'hello, world!$'

My code:

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.

Anyone knows it?

exsnake
  • 1,767
  • 2
  • 23
  • 44
  • Where are you telling int 10h the location of the string? Looking at the [docs](http://en.wikipedia.org/wiki/INT_10H) for int 10h, it's supposed to be in es:bp. – David Wohlferd Apr 26 '15 at 00:12
  • but how i can save a string in that memory segment?@DavidWohlferd – exsnake Apr 26 '15 at 00:47

1 Answers1

3

The suffix '$' as termination character is only available for certain DOS functions. INT 10h / AH=13h (Video-BIOS function) deals with the length of the string in CX. A "Pascal-string" has its length in the first byte. It has no termination character like a DOS-/C-/ASCIIZ-string. You can get TP manuals - especially the programmer's guide - from here.

Look at this example:

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.
rkhb
  • 14,159
  • 7
  • 32
  • 60