汇编:暑期小学期的第一天

今天是暑期小学期的第一天, 这个小学期的内容是Java和汇编。
昨天晚上看了一下老师放在网络学堂上的forward,其中What’s Wrong With Assembly Language的条目如下
• Assembly is hard to learn.
• Assembly is hard to read and understand.
• Assembly is hard to debug.
• Assembly is hard to maintain.
• Assembly is hard to write.
• Assembly language programming is time consuming.
• Improved compiler technology has eliminated the need for assembly language.
• Today, machines are so fast that we no longer need to use assembly.
• If you need more speed, you should use a better algorithm rather than switch to assembly
language.
• Machines have so much memory today, saving space using assembly is not important.
• Assembly language is not portable.
本来对汇编没有什么惧意的,但经过作者那么一吓,不禁对汇编重视一点了。其实那位作者想说明上面的观点是对汇编的误区,但看过那个作者的反驳之后觉得,上面的观点还是有道理的...


 
今天上课的时候惊奇的发现第一排坐着一个十岁的(有好事者后来问他)小男孩,拿着我们的书,上课还很认真的记笔记。真是奇迹,难道遇到了小神童?!



 毛希平老师为了说明汇编语言对理解高级程序设计语言是有裨益的就举了下面这个例子,问题那个关系成立:&a>&b>&c还是&a<&b<&c?
int  main()
... {
     int a=1;
     int b=2;
     int c=-1;
}
违反我直觉的是答案竟然是&a>&b>&c,毛老师说这和什么堆栈有关系,不过她也言之不详,所以我也没大搞明白。



我的第一个汇编程序,在MASM5上编译并链接运行成功:
data segment
    a    db    ?
    b    db    ?
    c     db     ?
    string    db     'c = $'
data ends

code segment
main proc far
    assume cs:code , ds:data , es:data
start:
    push    ds
    sub    ax , ax
    push     ax
    mov     ax , data
    mov     ds , ax
    mov     es , ax
    mov     a , 1
    mov    b , 2
    mov    al , a
    add     al , b
    mov    c , al
    lea     dx , string
    mov     ah , 09
    int    21h
    add     c , 30h
    mov    dl , c
    mov    ah , 2
    int     21h
    mov     dl , 0ah
    int    21h
    mov    dl , 0dh
    int    21h
    mov    dl , 0dh
    int    21h
    ret
main endp
code ends
end start

这个汇编程序所对应的C程序如下:
#include  < stdio.h >
int  main()
... {
    int a,b,c;
    a=1;
    b=2;
    c=a+b;
    printf("c=%d ",c);
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值