飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 2121|回复: 0

[C/C++] 第十六课作业(汇编转换大小写)

[复制链接]
  • TA的每日心情
    擦汗
    2016-4-19 21:35
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    发表于 2016-5-28 23:09:40 | 显示全部楼层 |阅读模式
    先写的C的代码,然后对比敲出来的
    只是简单的转换大小写,特殊符号也会被转换(这里之后修改)
    写在申请的空间中的,也没打印出来
    [Asm] 纯文本查看 复制代码
    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,[bp+4]
    	cmp ax,5Ah
    	ja high_1
    	jmp less_1
    for:
    	cmp bx,dx
    	jz retn_1
    	jmp begin
    
    retn_1:
            mov ax,24h
            mov [bp-48],ax
    	add sp,2
    	mov bp,si
    	mov sp,bp
    	pop bp
    	retn
    
    high_1:
    	sub al,20h
    	mov [bp-48],al
    	inc bp
    	inc bx	
    	jmp for	
    
    less_1:
    	add al,20h
    	mov [bp-48],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,[bp+2]
    	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代码
    [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);
    }


    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表