asm程序不起作用(nasm)

时间:2010-05-08 16:41:42

标签: assembly x86 nasm

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。 该程序应将小写字母变为大写字母。

2 个答案:

答案 0 :(得分:1)

看起来您正在尝试将字符串从小写转换为大写?问题是你只是将输入与字母'a'进行比较:

cmp al, 'a' 
jnb upper

如果要从小写转换为大写,则需要检查“a”到“z”范围内的字符,如果一次在该范围内,则减去32。

另外,我想你想在upper中将大写字母写回内存。您所做的只是更新寄存器,然后在loop1的下一次迭代中覆盖该寄存器。

这有帮助吗?

答案 1 :(得分:1)

我发现了我的问题: 当我输入文字时,'$' - 没有添加。

相关问题