2014-11-26 2 views
-1

저는 x86 NASM 코드로 직접 컴파일되는 C# 같은 언어를 만드는 중입니다. Console.ReadKey()와 비슷한 함수를 작성했습니다. 키를 기다린 다음 그 값을 문자열에 저장합니다. 다음은 ASM 함수의 코드입니다.키를 읽고 해당 키 값을 ASM의 변수에 저장하려면 어떻게합니까?

os_input_char: 
    pusha 
    mov di, ax    ; DI is where we'll store input (buffer) 
    call os_wait_for_key ; Moves the next char into al 
    stosb     ; Store character in designated buffer 
    mov al, 0    ; 0-terminate it 
    stosb     ; ^^ 
    popa 
    ret 

다음 코드에서이 함수를 호출합니다. 여기에 있습니다 :

type [kernel] 

:start 
string key = "a"; 
graphicsmode; 

nasm{ 
    mov bl, 0001b   ;blue 
    call os_clear_graphics ;clear 
}nasm 

movecursor(#0#, #0#); 
print("          "); 
print("  Welcome to LightningOS!   "); 
print("          "); 

:main1 
    readkey -> key; 
    //I put the key code into the variable "key" 

    println("you pressed: "+%key%); 
    //Now print the variable key 

    goto(main1); 
    //now loop back to main 

그리고 그냥 'a'를 인쇄합니다. 이제는 함수를 올바르게 호출한다고 확신합니다. 내 컴파일러는 C#으로 만들어 졌으므로 따를 것이 어렵지 않습니다. 'append'명령은 ASM 코드를 파일에 추가합니다. 전화 걸기 방법 :

  else if (line.StartsWith("readkey -> ") && line.EndsWith(";")) 
      { 
       append("mov ax, " + line.Substring(11, line.Substring(11).Length - 1)); 
       append("call os_input_char"); 
      } 

그럼 ... 어떻게 실제로 그 키를 문자열로 가져 와서 그 문자열을 인쇄합니까?

+0

여기에 좋은 읽을 거리가 될 것입니다 ..- http://stackoverflow.com/questions/8629188/asm-interpreter-how-are-local-variables-stored – MethodMan

답변

0

몇 가지 아이디어 :
stosb을 사용하고 있지만 ES를 설정하지 않았습니다. 벌써 괜찮은거야?
line.Substring은 0 기반 색인 또는 1 기반 색인을 사용합니까?

관련 문제