wai1216 发表于 2016-5-28 23:09:40

第十六课作业(汇编转换大小写)

先写的C的代码,然后对比敲出来的
只是简单的转换大小写,特殊符号也会被转换(这里之后修改)
写在申请的空间中的,也没打印出来
assume cs:code
set segment

db 100h dup(0)

set ends

data segment

str db 'Hello$'

data ends

code segment
;<<<<<<<<<<< 函数开始
ascii_c:
        push bp
        mov bp,sp
        mov si,sp
        sub sp,2
               
        mov bx,0
;>>>>>>>>>>>>for(),大小写转换
begin:
        mov al,
        cmp ax,5Ah
        ja high_1
        jmp less_1
for:
        cmp bx,dx
        jz retn_1
        jmp begin

retn_1:
      mov ax,24h
      mov ,ax
        add sp,2
        mov bp,si
        mov sp,bp
        pop bp
        retn

high_1:
        sub al,20h
        mov ,al
        inc bp
        inc bx       
        jmp for       

less_1:
        add al,20h
        mov ,al
        inc bp
        inc bx       
        jmp for
;>>>>>>>>>>>>main()
start:
        mov ax,set
        mov ss,ax
        mov sp,100h

        mov ax,0
        mov dx,0
        mov bp,sp
        sub bp,2
;>>>>>>>>>>>>取长度+调用函数
get_s:
        mov al,
        cmp ax,24h
        jnz strlen
        call ascii_c
        add bp,2

        mov ax,4c00h
      int 21h

strlen:
        inc dx
        inc bp
        jmp get_s


code ends
end start
---------------------
附上相应的C代码
void as(char *s)
{
        while(*s)
        {
                if(*s >= 'a' && *s <= 'z')
                {
                        *s -= 32;
                }
                else if(*s >= 'A' && *s <= 'Z')
                {
                        *s +=32;
                }
                printf("%c",*s++);
        }
}
main()
{
        char c[] = "Hello,World";
        printf("%s\n",c);
        as(c);
}

页: [1]
查看完整版本: 第十六课作业(汇编转换大小写)