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

我的博客

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

[2011-10-12 10:59] 第十章实验1和2

assume cs:codesg

datasg segment
;string
    db 'My name is YangKunLong.', 0
;160--the bytes per line, help to calculate   -----and color for display
    db 160,01000010B
    ;start at ds:[26], to storage the temp variable of the divdw.
    dw 8 dup (0)
datasg ends

stacksg segment
    dw 16 dup (0)
stacksg ends

codesg segment
main:   mov ax, datasg
        mov ds, ax
        mov ax, stacksg
        mov ss, ax
        mov sp, 16
        
        mov ax, 0B800h
        mov es, ax

        mov si, 0
        mov dh, 8
        mov dl, 3
        mov ch, 0
        mov cl, ds:[25]
        call show_str

        mov ax, 4240H
        mov dx, 000FH
        mov cx, 0AH
        call divdw
        
        mov ax, 4c00h
        int 21h
;;function : cannot overflow div
;;        dx -- higher 16bit of dividend   ax- lower 16bit of dividend        cx -- divisor
;;return  dx -- higher 16 bit of result    ax -- lower 16bit of result        cx --remainder
divdw:
        push bx
        mov ds:[26], ax
        mov ds:[28], dx
        mov ds:[30], cx

        ;; H/N
        mov ax, dx
        mov dx, 0
        div cx
        mov ds:[32], ax ;int(H/N)
        mov ds:[34], dx ;rem(H/N)
                
        ;storage (int)H/N * 65536 
        ;mov ds:[36], 0000H
        mov ds:[38], ax
        ;calc (rem)H/N *65536
        mov dx, ds:[34]
        mov ax, 0
        ;(rem)H/N * 65536 + L
        add ax, ds:[26]
        ;((rem)H/N * 65536 + L)/N
        div cx
        
        mov cx, dx    ;存余数
        ;两项相加
        mov dx, ds:[38]
        add ax, ds:[36] ; +0 可以不做
        
        pop bx       
        ret

;;function : show a string with 0 ended at certain position and color
;;dh--line no.    dl--column no.
;;cl--color       ds:si--the beginning of the string
;;return none
show_str:
        push bx
        push si 
        push ax
        push cx  
        
        ;;calculate the first address of the string in video memory
        mov al, dh
        mul byte ptr ds:[24]
        mov bx, ax
        add bx, si
        add bx, si
        mov ah, 0
        mov al, dl
        add bx, ax
        add bx, ax
        
change: 
        mov cl, [si]
        mov ch, 0
        jcxz ok        

        mov es:[bx], cl
        pop cx
        mov byte ptr es:[bx+1], cl
        push cx
        inc si
        inc bx
        inc bx
        jmp short change
                
    ok: pop cx
        pop ax
        pop si
        pop bx
        ret

codesg ends
end main
评论次数(0)  |  浏览次数(378)  |  类型(汇编作业) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码