+ -
当前位置:首页 → 问答吧 → 求一道简单汇编实验题代码

求一道简单汇编实验题代码

时间:2011-05-05

来源:互联网

从键盘输入一个两位数N 将结果保存在N中;求1+2+3+。。。+n的和结果保存在变量SUM中,将sum的内容按16进制输出

作者: viking33   发布时间: 2011-05-05

没对输入做检查,楼主自行修改
Assembly code

assume    cs:code,ds:data
data    segment
buff    db    3,?,2 dup (0)
data    ends
code    segment
start:
    mov ax,data
    mov ds,ax
    mov ah,10
    mov dx,offset buff
    int 21h
    mov ah,2
    mov dl,13
    int 21h
    mov dl,10
    int 21h
    mov al,buff+1
    cmp al,2
    jnz exit
    mov al,buff+2
    sub al,30h
    mov cl,10
    mul cl
    mov bl,buff+3
    sub bl,30h
    add al,bl
    mov dx,ax
    mov cx,dx
    dec cx
s:
    add dx,cx
    loop s
    call dispdec    
exit:
    mov ah,4ch
    int 21h
;input:dx
dispdec    proc uses dx
    mov ax,dx
    xor dx,dx
    mov bx,10
    mov cx,0
a:    cmp ax,10
    jb ok
    div bx
    add dl,30h
    push dx
    xor dx,dx
    inc cx
    jmp a
ok:    add al,30h
    push ax
    inc cx
b:    pop dx
    mov ah,2
    int 21h
    loop b
    ret
dispdec    endp
;
code    ends
end    start


作者: masmaster   发布时间: 2011-05-05

哦, 还以为显示十进制呢!!下面代码是显示16进制子程序。
Assembly code

;要显示的值在DX这里。
disphex proc uses dx
        mov cx,4
d1:     push cx
        mov cl,4
        rol dx,cl
        push dx
        and dx,0fh
        cmp dl,10
        jb d10
        add dl,37h
        mov ah,2
        int 21h
        jmp jx2
d10:    add dl,30h
        mov ah,2
        int 21h
jx2:    pop dx
        pop cx
        loop d1
        ret
disphex endp

作者: masmaster   发布时间: 2011-05-05

再完整点就好了……机房coding中,各种不会

作者: linda28king4ELF   发布时间: 2011-05-05