试验十 3.数值显示

October 11, 2013
masm

题目的意思是:

  把一个16进制的数字转化成十进制,然后在屏幕的第3行,第8列,用绿色输出。

这货倒是不太难,就是学会调用之前写过的函数就行了==

assume cs:code, ds:data, ss:stack

data segment
    db 10 dup(0)
data ends

stack segment
    dw 10 dup(0)
stack ends

code segment
start:
    mov ax, 12666
    mov dx, 0
    mov bx, data
    mov ds, bx
    mov si, 0
    call dtoc

    mov dh, 8
    mov dl, 3
    mov cl, 2
    call show_str

    mov ax, 4c00h
    int 21h

dtoc:
    push si
    mov bx, 10
    mov cx, ax
    mov di, 0
sad:
    div bx
    add dx, 30h
    push dx
    mov dx, 0
    inc di
    mov cx, ax
    add cx, 1
    loop sad

    mov bp, 0
    mov cx, di
ago:
    pop dx
    mov al, dl
    mov ds:[bp], al
    inc bp
    loop ago

    mov ds:[bp], 0

    pop si

    ret

show_str:
    push dx
    push cx

    ;row
    dec dh
    mov al, 0a0h
    mul dh
    push ax

    ;col
    dec dl
    mov al, 2h
    mul dl

    pop bx
    add ax, bx
    mov di, 0b800h
    mov es, di
    mov bp, ax
    mov bl, cl

change:
    mov cl, [si]
    mov ch, 0
    jcxz ok
    mov di, si
    add di, di
    mov al, ds:[si]
    mov byte ptr es:[bp+di], al
    mov byte ptr es:[bp+di+1], bl
    inc si  
    jmp short change
ok:
    pop cx
    pop dx
    ret

code ends
end start

虽然很长……看起来好腻害的样子=_=

其实只要注意在函数开始的时候把要修改的寄存器的值压栈,结束的时候要出栈,就可以了

没怎么优化==

comments powered by Disqus