2013-07-04 28 views
-2

這是整個文件和disp_str將在* .c文件如何改變這種功能(disp_str)到64位版本

使用,我是新來的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格式。

此代碼是由我在書中找到的。 我猜這個代碼是在屏幕上打印一個字符串,是不是?

+1

我建議你簡單地將函數轉換回C然後用64位編譯器編譯它。 – sh1

+0

你知道,這段代碼是我在書中找到的。我不知道「轉換回C」是什麼意思? –

回答

1

的代碼看起來是文本寫入,其中每一個細胞被含有顏色信息的字節中描述的80列PC文本模式式緩衝器, (四位 前景,一個位閃爍,三位背景)和字符 的一個字節設置爲白色黑色或白色黑色。

但是,它不處理滾動,它不處理比80 字符長的行,並且它不更新硬件遊標。

它使用gs:段覆蓋寫入輸出,這表明它可能會直接進入視頻內存,這表明它可能是 ;但是我沒有看到該代碼中設置的描述符爲 ,所以我不知道它應該具有什麼價值。這可能是您的操作系統或DOS擴展程序或您擁有的任何標準的 。

我不認爲你需要將它轉換爲64位,因爲你的電腦應該支持運行32位代碼的 。

但是,如果您確實需要這樣做,您可以嘗試編譯這個代碼,我認爲它大致相當。

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; 
} 
+0

謝謝。我猜想github可能有一個。 –

+0

@ guotong1988,這本書是什麼?如果我們知道書名,指出適當的來源可能會更容易。 – sh1

+0

這是一本名爲「OS From Scratch」的中文書籍。 –