8086汇编学习小记王爽汇编语言实验10

 1 ;解决除法溢出的子程序,(商为32位时的溢出)
 2 assume cs : codesg, ds : datasg, ss : stacksg
 3 
 4 datasg SEGMENT
 5 db 'welcome to masm!'
 6 datasg ENDS
 7 
 8 stacksg SEGMENT
 9 dw 8 dup (0)
10 stacksg ENDS
11 
12 codesg SEGMENT
13 
14 
15 start:    
16 mov ax, stacksg
17 mov ss, ax
18 mov sp, 16
19 
20 mov ax, 4240h
21 mov dx, 0fh
22 mov cx, 0ah
23 
24 call divdw
25 
26 mov ax, 4c00h
27 int 21h
28 
29 divdw:    push ax    ;保存低位被除数
30 ;以下3行计算高位除以除数的得数和余数,分别在ax,dx里
31 mov ax, dx 
32 mov dx, 0
33 div cx
34 
35 mov si, ax ;高位商,即溢出部分
36 ;下2行计算不会出现溢出,dx为高位除法过后的余数即新的高位,ax任为原来的地位
37 pop ax    
38 div cx
39 ;把余数赋给cx,除数高位在dx,地位在ax
40 mov cx, dx
41 mov dx, si
42 ret
43 codesg ENDS
44 END start
原文地址:https://www.cnblogs.com/ACystalMoon/p/2755927.html