1. 程式人生 > >《組合語言》實驗十答案

《組合語言》實驗十答案

實驗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
sub si,si
call show_str
mov ax,4c00h
int 21h
show_str:
mov ax,0b800h
mov es,ax
mov ax,160
mul dh
sub dh,dh
add dl,dl
add ax,dx
mov di,ax
change:
push cx
mov cl,[si]
jcxz ok
pop cx
mov al,[si]
mov ah,cl
mov es:[di],ax
add di,2
inc si
jmp short change
ok:
pop cx
ret
code ends
end start

實驗10.2

assume cs:code
code segment
start:
mov ax,4240h
mov dx,0fh
mov cx,0ah
call divdw
mov ax,4c00h
int 21h
divdw:
push ax   ;被除數低位入棧
mov ax,dx
sub dx,dx
div cx    ;此時ax=(H/N)的商,dx=(H/N)的餘數
mov bx,ax
pop ax
div cx
mov dx,bx
ret
code ends
end start

實驗10.3

assume cs:code
data segment
db 16 dup (0)
data ends
code segment
start:
mov ax,12666
mov bx,data
mov ds,bx
sub si,si
call dtoc
mov ax,4c00h
int 21h
dtoc:
mov bx,10
sub di,di  ;di為計數器
change:
sub dx,dx
div bx    ;ax=商,dx=餘數
mov cx,ax     
add dx,30h
push dx
inc di
jcxz ok
jmp short change
ok:
mov cx,di
s:
pop [si]
inc si
loop s
ret
code ends
end start