assume cs:code, ds:data, ss:stack
data segment
db 'welcome to masm!'
data ends
stack segment
dw 32 dup (0)
stack ends
code segment
start:
;;设置栈
mov ax, stack
mov ss, ax
mov sp, 40h
mov ax, 0005
mov dx, 0002
mov cx, 02h
call divdw
mov ax, 4c00h
int 21h
;;名称 divdw
;;功能: 进行不会溢出的除法运算,被除数为dword类型, 除数为word类型,结果为 dword类型
;;
;;参数 :
;; (ax)= 被除数的低16位
;; (dx)= 被除数的高16位
;; (cx) 除数
;;
;; 结果:
;; (ax)= 结果的低16位, (dx)= 被除数的高16位
;; (cx) 除数
divdw:
push di
push si
push bx
mov di, dx;save the value of dx
mov si, ax;save the value of ax
mov ax, dx
mov dx, 0
div cx; after this, (ax) = H/N
push ax
mov bx, 0
push bx ; ruzhan ax:0000 == int(H/N)*65536
mov ax, si
div cx; after this (ax) = [rem[H/N]*65536+L]/N
mov cx, dx
pop dx
pop dx; after this ax
pop si
pop di
pop bx
ret
code ends
end start
网友评论