2010-05-08 53 views
0
org 0x100 
SEGMENT .CODE 
    mov ah,0x9 
    mov dx, Msg1 
    int 0x21 

    ;string input 
    mov ah,0xA 
    mov dx,buff 
    int 0x21 
    mov ax,0 
    mov al,[buff+1]; length 

    ;string UPPERCASE  
    mov cl, al 
    mov si, buff 
    cld 
loop1: 
    lodsb; 
    cmp al, 'a' 
    jnb upper 
loop loop1 
;output 
mov ah,0x9 
mov dx, buff 
int 0x21 

exit: 
    mov ah, 0x8 
    int 0x21 
    int 0x20 
upper: 
    sub al,32 
    jmp loop1 
SEGMENT .DATA 
Msg1 db 'Press string: $' 
buff db 254,0 

此代碼不起作用。 我認爲問題出在jnb upper。 這個程序應該把小寫字母變成大寫字母。asm程序不起作用(nasm)

+1

你的問題是什麼?你只是簡單地描述一些代碼,並假設性能不佳。 – Oded 2010-05-08 16:46:41

+0

我不知道爲什麼我的程序無法正常工作。 – GLeBaTi 2010-05-08 16:49:06

+1

我想他想將小寫字母轉換爲大寫字母。 – nc3b 2010-05-08 16:50:15

回答

1

我發現我的問題: 當我輸入文本時,'$' - 沒有添加。

+0

+1跟進 – 2010-05-19 14:29:31

1

它看起來像你試圖從小寫字母轉換爲大寫字母?問題是,你只比較輸入對字母「A」:

cmp al, 'a' 
jnb upper 

如果你想從小寫轉換爲大寫,則需要從「A」到範圍檢查字符「Z ',如果曾經在那個範圍內,然後減去32.

另外,我認爲你想寫大寫char回到內存中upper。你所做的只是更新寄存器,然後在loop1的下一次迭代中被覆蓋。

這有幫助嗎?

+1

JNB上:它會跳到_only_如果它比大於或等於。我不認爲他需要進行其他比較。他沒有將價值回寫到緩衝區這一事實是真正的問題。 – nc3b 2010-05-08 17:02:01

+0

和我必須做什麼? (我是不是很久以前就開始學習彙編) – GLeBaTi 2010-05-08 17:12:46

+0

@ nc3b - 良好的漁獲物,但他仍然需要確保它並不比「Z」 – 2010-05-08 22:29:14