《왕상-집성어》 P206 실험실 10 세 번째 문제의 답안

1348 단어
assume cs:code, ds:data, ss:stack

data segment
	db 10 dup (0)
data ends

stack segment
	db 16 dup (0)
stack ends

code segment

start:	
	mov ax, 123
	mov bx, data
	mov ds, bx
	mov bx, stack
	mov ss, bx
	mov sp, 16
	call dtoc
		
	mov dh, 8
	mov dl, 3
	mov cl, 2
	call show_str
		
	mov ax, 4c00H
	int 21H		
		
dtoc:              ;start of function dtoc
	push ax
	push bx
	push cx
	push dx
	push si
	push di
	
	mov si, 0 
	mov dx, 0
	mov bx, 10
	div bx     ;div  ,bx  16   ,dx ax     ,    ax ,     dx 
	mov cx, ax ;         
L:	
	push dx
	inc si
	jcxz s1
	mov dx, 0
	div bx
	mov cx, ax
	jmp L
	
s1:
	mov di, 0 
s3:	mov cx, si
	jcxz s2
	pop ax
	add al, 30H
	mov ds:[di], al
	inc di
	dec si
	loop s3
s2:
	mov byte ptr ds:[di], 0 ;           0,   show_str       0   
	pop di
	pop si 
	pop dx
	pop cx
	pop bx
	pop ax
	ret
	
	; end of function dtoc
	
show_str:
	push ax
	push bx
	push cx
	push dx
    push es

	mov ax, 0b800h
	mov es, ax    ;es            
	mov al, dh
	mov ch, 0A0H
    mul ch 
	add dl, dl
    mov dh, 0
	add ax, dx
    mov bx, ax    ;      、   ,           
    mov al, cl    ;      ,   al ,      jcxz,    cl   
s0: mov ch, 0
    mov cl, ds:[si]
    jcxz s
	mov es:[bx], cl
    mov es:[bx+1], al
	inc si
    add bx, 2
    jmp s0
    
s:	
	pop es
	pop dx
	pop cx
	pop bx
	pop ax
	ret
code ends
end start

좋은 웹페이지 즐겨찾기