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

我的博客

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

[2010-09-05 22:04] 习题4.13

按要求分别编写如下功能子程序:把由十进制数ASCII码组成的字符串转换为对应的数值。过程suba通过寄存器传递入口参数,通过寄存器传递出口参数;过程subb通过堆栈传递入口参数,通过寄存器传递出口参数;其他参数自定。

答:
;-----------------------------------------------------
assume  cs:code,ds:data,ss:stack
stack   segment stack
        db      128     dup(0)
stack   ends
data    segment
num     db      '12345'
tab     dw      10000,1000,100,10,1
sum     dw      0
data    ends
code    segment
start:
        mov ax,data
        mov ds,ax
        mov si,offset num
        mov di,offset tab
        mov cx,5
        xor ax,ax
s:      mov ax,[di]
        mov bx,[si]
        and bx,0fh
        mul bx
        add sum,ax
        inc si
        add di,2
        loop s
;
        mov ax,sum         ;利用寄存器传递参数
        call suba
        push sum           ;利用栈传递参数
        call subb
        mov ah,4ch
        int 21h
;
suba    proc
        mov bx,10
        xor dx,dx
s1:     div bx
        push dx
        xor dx,dx
        cmp ax,10
        jb ok
        jmp s1
ok:     push ax
        mov cx,5
s2:     pop dx
        add dx,3030h
        mov ah,2
        int 21h
        loop s2
        ret
suba    endp
;
subb    proc
        push bp
        mov bp,sp
        mov ax,[bp+4]
        mov bx,10
        xor dx,dx
s1:     div bx
        push dx
        xor dx,dx
        cmp ax,10
        jb ok
        jmp s1
ok:     push ax
        mov cx,5
s2:     pop dx
        add dx,3030h
        mov ah,2
        int 21h
        loop s2
        pop bp
        ret
subb    endp
;
code    ends
end     start
;-----------------------------------------------------
评论次数(0)  |  浏览次数(294)  |  类型(汇编习题集) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码