10_1显示字符串

assume cs:code
data segment
        db 'welcome to masm!',0
data ends

code segment
start:  mov dh,8
        mov dl,3
        mov cl,2
        mov ax,data
        mov ds,ax
        mov si,0
        call show_str
        mov ax,4c00h
        int 21h
show_str:       push dx
                push cx
                push si
                mov di,0
                mov bl,dh
                dec bl
                mov al,160
                mul bl
                mov bx,ax
                add dl,dl
                add bl,dl
        mov ax,0b800h
        mov es,ax
        mov al,cl
         s:     mov ch,0
                mov cl,ds:[si]
                jcxz ok
                mov es:[bx+di],cl
                mov es:[bx+di+1],al
        add di,2
        inc si
                loop s
         ok:    pop dx
                pop cx
                pop si
                ret
code ends
end start
           
                

10_2解决除法溢出的问题

assume cs:code,ss:stack

stack segment
        dw 8 dup (0)
stack ends

code segment
start:  mov ax,stack
        mov ss,ax
        mov sp,16
        mov ax,4240h
        mov dx,00fh
        mov cx,0ah
        call divdw
        mov ax,4c00h
        int 21h

divdw:  push ax
        mov ax,dx
        mov dx,0
        div cx

        mov bx,ax
        pop ax
        div cx
        mov cx,dx
        mov dx,bx
        ret
code ends
end start

10_3数值显示

assume cs:code

data segment
        db 10 dup (0)
data ends

stack segment
    dw 8 dup(0)
stack ends

code segment
start:  mov ax,42243
    mov bx,data
    mov ds,bx
    mov bx,stack
    mov ss,bx
    mov sp,10h
    mov si,0
    call dtoc

    mov dh,8
        mov dl,3
        mov cl,2
        call show_str
        mov ax,4c00h
        int 21h

dtoc:    push ax
    push bx
    push si
    mov bx,10
    mov si,0
    
  s0:    mov dx,0
    div bx
    add dx,30h
    push dx
    mov cx,ax
    inc si
    inc cx
    loop s0
    
    mov cx,si
    mov si,0
  s1:    pop ds:[si]
    inc si
    loop s1

       pop si
    pop bx
    pop ax
    ret
    

show_str:   push ax
        push dx
                push cx
                push si
                mov di,0
                mov bl,dh
                dec bl
                mov al,160
                mul bl
                mov bx,ax
                add dl,dl
                add bl,dl
        mov ax,0b800h
        mov es,ax
        mov al,cl
         s:     mov ch,0
                mov cl,ds:[si]
                jcxz ok
                mov es:[bx+di],cl
                mov es:[bx+di+1],al
        add di,2
        inc si
                loop s
         ok:    pop si
                pop cx
                pop dx
        pop ax
                ret
code ends
end start