汇编网首页登录博客注册
masmaster的学习博客
博客首页博客互动【做检测题】论坛求助

我的博客

个人首页 |  我的文章 |  我的相册 |  我的好友 |  最新访客 |  文章收藏 |  论坛提问 |  友情链接 |  给我留言  
图片载入中
文章收藏

[2010-09-02 21:19] 习题3.29

请写出一个把两个字符串合并的示例程序。

答:

;-----------------------------------------------------
;合并字符串
;将str1与str2合并,结果放在newstr
assume  cs:code,ds:data
data    segment
str1    db      'hello!,'
;指定编译地址,偏移值任意
        org     8h
str2    db      'world!'
;为新串预留空间
newstr  db      (($-offset str2)+(offset str2-offset str1)) dup (0)  
;建立字串地址:长度表,便于寻址。
list    dw      offset str1,lengthof str1,offset str2,lengthof str2  
data    ends
code    segment
start:
        mov ax,data
        mov ds,ax
        mov bx,offset list        ;DS:BX=地址表地址
        mov cx,(lengthof list)/2  ;
        mov di,offset newstr      ;DS:DI=新串地址
L:      push cx                   ;保护计数器
        mov si,[bx]               ;DS:SI=字串首地址
        mov cx,[bx+2]             ;字节字串长度
L1:     mov al,[si]               ;开始复制数据
        mov [di],al               ;
        inc si                    ;指向下一个字符
        inc di                    ;指向下一个单元
        loop L1
        pop cx                    ;恢复计数器
        add bx,4                  ;指向下一个地址
        loop L
        mov ah,4ch
        int 21h
code    ends
end     start
;-----------------------------------------------------
评论次数(0)  |  浏览次数(300)  |  类型(汇编习题集) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码