-2

これはファイル全体disp_strで、*.c ファイルで使用されます

そして、私はgithubが初めてです。

このファイルの 64 ビット版があれば、そこから学ぶことができます。

[SECTION .data]
disp_pos    dd  0

[SECTION .text]

global  disp_str

; ========================================================================
;                  void disp_str(char * info);
; ========================================================================
disp_str:
    push    ebp
    mov ebp, esp

    mov esi, [ebp + 8]  ; pszInfo
    mov edi, [disp_pos]
    mov ah, 0Fh
.1:
    lodsb
    test    al, al
    jz  .2
    cmp al, 0Ah 
    jnz .3
    push    eax
    mov eax, edi
    mov bl, 160
    div bl
    and eax, 0FFh
    inc eax
    mov bl, 160
    mul bl
    mov edi, eax
    pop eax
    jmp .1
.3:
    mov [gs:edi], ax
    add edi, 2
    jmp .1

.2:
    mov [disp_pos], edi

    pop ebp
    ret

私のコンピュータは 64 ビットなので、64 フォーマットに変換する必要があります。

このコードは、私が本の中で見つけました。このコードは、画面に文字列を出力するためのものだと思いますが、正しいですか?

4

1 に答える 1

1

このコードは、80 列の PC テキスト モード スタイル バッファーにテキストを書き込んでいるように見えます。ここで、すべてのセルは、色情報 (前景 4 ビット、瞬き 1 ビット、背景 3 ビット) を含む 1 バイトと、文字の 1 バイトによって記述されます。すべてを黒地に白、または白地に黒に設定します。

ただし、スクロールは処理されず、80 文字を超える行は処理されず、ハードウェア カーソルは更新されません。

セグメント オーバーライドを使用gs:して出力に書き込みます。これは、おそらくビデオ メモリに直接書き込まれることを示唆しています。しかし、その記述子がそのコードで設定されているのがわからないので、どのような値が必要かわかりません。これは、お使いの OS や DOS エクステンダなど、お持ちのものの標準である可能性があります。

とにかく、コンピューターは32ビットコードの実行をサポートする必要があるため、64ビットに変換する必要はないと思います。

ただし、何らかの理由でそれを行う必要がある場合は、この C コードをコンパイルしてみてください。これはほぼ同等だと思います。

extern short *disp_ptr;
void disp_str(char *s)
{
    int c;
    /* fetch the current write position */
    short *p = disp_pos;

    /* read characters from the string passed to the function, and stop
     * when we reach a 0.
     */
    while ((c = *s++) != '\0')
    {
        /* If we see a newline in the string:
         */
        if (c == '\n')
        {
            intptr_t i = (intptr_t)p;

            /* round the address down to a multiple of 160 (80 16-bit
             * values), and add one to advance the write pointer to the
             * start of the next line.
             */
            i /= 160;
            i = (i & 255) + 1;
            i *= 160;
            p = (void *)i;
        }
        else
        {
            /* write the character to the screen along with colour
             * information
             */
            *p++ = c | 0x0f00;
        }
    }

    /* write the modified pointer back out to static storage. */
    disp_pos = p;
}
于 2013-07-04T20:12:48.623 に答える