當前位置:名人名言大全網 - 人生格言 - 匯編語言用8086指令集和寄存器做32位有符號數學運算

匯編語言用8086指令集和寄存器做32位有符號數學運算

輸入輸出的ASC轉換我想妳是會是,所以就不寫了。我只提供32位運算程序。以下程序是試算通過的。

1、在數據段定義4個運算變量

;===============================

;32位運算變量

;===============================

data4 dw ?

data3 dw ?

data2 dw ?

data1 dw ?

2、以下是加、減、乘、除的4個子程序

;*******************************

;32位運算

;*******************************

;===============================

;32位符號數的加法運算

;入: DXAX=32位操作數1

; CXBX=32位操作數2

;出: DXAX=兩操作數的和

; OF=1: 溢出

; OF=0: 正常

;===============================

subn_add32 proc near

add ax,bx

adc dx,cx

ret

subn_add32 endp

;===============================

;32位符號數的減法運算

;入: DXAX=32位操作數1

; CXBX=32位操作數2

;出: DXAX=操作數1-操作數2的差

; OF=1: 溢出

; OF=0: 正常

;===============================

subn_sub32 proc near

sub ax,bx

sbb dx,cx

ret

subn_sub32 endp

;===============================

;32位符號數的乘法運算

;入: DXAX=32位操作數1

; CXBX=32位操作數2

;出: CXBXDXAX=兩操作數積

;===============================

subn_mul32 proc near

push di

xor di,di

test dh,80h

jz sss_1

mov di,1

not dx

not ax

add ax,1

adc dx,0

sss_1:

test ch,80h

jz sss_2

not cx

not bx

add bx,1

adc cx,0

xor di,1

sss_2:

call subn_32x32

test di,1

jz sss_out

not ax

not bx

not cx

not dx

add ax,1

adc dx,0

adc bx,0

adc cx,0

sss_out:

pop di

ret

subn_mul32 endp

;===============================

;32位符號數的除法運算

;入: DXAX=32位被除數

; CXBX=32位除數

;出:DXAX=商

; CXBX=余數(絕對值)

;===============================

subn_div32 proc near

push di

xor di,di

test dh,80h

jz sss_1

mov di,1

not dx

not ax

add ax,1

adc dx,0

sss_1:

test ch,80h

jz sss_2

not cx

not bx

add bx,1

adc cx,0

xor di,1

sss_2:

call subn_32v32

test di,1

jz sss_out

not ax

not dx

add ax,1

adc dx,0

sss_out:

pop di

ret

subn_div32 endp

;*******以下是內部子程序********

;===============================

;無符號數的32位值乘32位值

;入: DXAX=被乘數

; CXBX=乘數

;出: cx=積的高64位

; bx=積的高48位

; dx=積的高32位

; ax=積的低16位

;===============================

subn_32x32 proc near

push si

push di

mov data1,0

mov data2,0

mov data3,0

mov data4,0

mov si,ax

mov di,dx

mul bx

mov data2,dx

mov data1,ax

mov ax,di

mul bx

add data2,ax

adc data3,dx

mov ax,si

mul cx

add data2,ax

adc data3,dx

adc data4,0

mov ax,di

mul cx

add data3,ax

adc data4,dx

mov cx,data4

mov bx,data3

mov dx,data2

mov ax,data1

pop di

pop si

ret

subn_32x32 endp

;===============================

;無符號數的32位值除以16位值

;入:DXAX=被除數

; CX=除數

;出:DXAX=商

; BX=余數

;===============================

subn_32v16 proc near

push ax

mov ax,dx

mov dx,0

div cx

mov bx,ax

pop ax

div cx

xchg bx,dx

ret

subn_32v16 endp

;===============================

;無符號數的32位值除以32位值

;入:DXAX=被除數

; CXBX=除數

;出:DXAX=商

; CXBX=余數

;===============================

subn_32v32 proc near

test cx,cx

jnz sss_1

mov cx,bx

call subn_32v16

xor cx,cx

ret

sss_1:

push di

xor di,di

sss_lp1:

sub ax,bx

sbb dx,cx

jc sss_out

inc di

jmp sss_lp1

sss_out:

add bx,ax

adc cx,dx

mov ax,di

mov dx,0

pop di

ret

subn_32v32 endp