2011-09-29 23 views
1

我正在編寫提示用戶輸入小寫字符串的彙編代碼,然後用所有UPPER-CASE字符輸出相同的字符串。我的想法是遍歷從特定地址開始的字節,並從每個字節中減去20H(將小寫變爲大寫),直到達到具有特定值的字節。我對Assembly並不熟悉,所以我不確定這樣的循環的語法是什麼樣子。通過內存遍歷編輯每個字節

任何人都可以提供一些示例代碼或直接我在哪裏可以找到這樣的語法的例子?

任何幫助,非常感謝!

+0

我認爲的作業? –

+0

爲什麼不研究'gcc -S'的輸出來實現解決方案的C實現? –

+0

你對ASM的熟悉程度如何?因爲如果你只知道非常非常基本的東西(mov,add,jz),我就不會看到問題了。 –

回答

5

通常,字符串終止於零(0x00十六進制)。假設這是你選擇做的事,下面是一些示例代碼。我不確定你正在使用哪個彙編程序,甚至是哪種語法,但是這個x86代碼應該可以在MASM中工作:

mov cl, 0    ; cl is the counter register, set it to 
         ; zero (the first character in the string) 

start:    ; Beginning of loop 
    mov al, bytes[cl] ; Read the next byte from memory 

    cmp al, 0   ; Compare the byte to null (the terminator) 
    je end    ; If the byte is null, jump out of the loop 

    sub al, 20h   ; Convert to upper case 
         ; A better solution would be: and al, 0DFh 

    ; Output the character in al 

    add cl, 1   ; Move to the next byte in the string 
    jmp start   ; Loop 
end: 
1

嗯,一個簡潔的(但不是最適合當前的處理器性能)的選擇是:

  • 有一些類型的計數器來控制循環
  • 點DS:SI與ES:DI在開始
  • 做LODSB,和人,DFH,STOSB序列中的循環