📄 procedure1.asm
字号:
je output1
loopFor11: ; continue to do Quotient and Remainder until take off Dividend
call Cycle
inc esi
loop loopFor11
jmp output1
toJudge6:
call EqualNumbers ;number Dividend equal number of Divisor ,do Quotient and Remainder
mov bl , Quotient1
mov Quotient , bl
mov count2 ,0
inc count2
mov ecx , count1
sub ecx , count
je output1
lea esi , nobcd1
add esi , count
jmp loopFor11
output1:
lea esi , Quotient
lea edi , result
mov ecx , count2
call NOBCDTOASC ;Quotient into ASCII and output it
output label4
output result
lea esi , Median1
lea edi , lastRemainder
mov ecx , count3
call NOBCDTOASC ;lastRemainder into ASCII and output it
output label5
output lastRemainder ;
exit2:
popad
pop ebp
ret
Divis ENDP
;********************************************************************
; 把ASCII码转化为压缩的BCD码
;********************************************************************
ASCTOBCD PROC NEAR32 ; find length of source string and move ESI to trailing null
push ebp
mov ecx, 0 ; count := 0
while1:
cmp BYTE PTR [esi], 0 ; while not end of string (null)
jz endwhile1
inc ecx ; add 1 to count of characters
inc esi ; point at next character
jmp while1 ; check again
endwhile1: ; process source characters a pair at a time
while2:
cmp ecx, 0 ; while count > 0
jz endwhile2
dec esi ; point at next ASCII byte from right
mov al, BYTE PTR [esi] ; get byte
and al, 00001111b ; convert to BCD digit
mov BYTE PTR [edi], al ; save BCD digit
dec ecx ; decrement count
jz endwhile2 ; exit loop if out of source digits
dec esi ; point at next ASCII byte from right
mov al, BYTE PTR [esi] ; get byte
shl al, 4 ; shift to left and convert to digit
or BYTE PTR [edi], al ; combine with other BCD digit
dec ecx ; decrement count
inc edi ; point at next destination byte
jmp while2 ; repeat for all source characters
endwhile2:
pop ebp
ret
ASCTOBCD ENDP
;********************************************************************
; 把压缩的BCD码转化为ASCII码
;********************************************************************
BCDTOASC PROC NEAR32
; convert 10 byte BCD number at to 19 byte long ASCII string
; parameter 1: address of BCD number
; parameter 2: destination address
; author: R. Detmer revised: 5/98
push ebp
lea edi , result
add edi, 18 ; point to last byte of destination
mov ecx, 9 ; count of bytes to process
for1:
mov al, [esi] ; byte with two bcd digits
mov ah, al ; copy to high order byte of AX
and al, 00001111b ; mask out higher order digit
or al, 30h ; convert to ASCII character
mov [edi], al ; save lower order digit
dec edi ; point at next destination byte to left
shr ah, 4 ; shift out lower order digit
or ah, 30h ; convert to ASCII
mov [edi], ah ; save higher order digit
dec edi ; point at next destination byte to left
inc esi ; point at next source byte
loop for1 ; continue for 9 bytes
mov BYTE PTR [edi], ' ' ; space for positive number
and BYTE PTR [esi], 80h ; check sign byte
jz nonNeg ; skip if not negative
mov BYTE PTR [edi], '-' ; minus sign
nonNeg:
pop ebp
ret ; return, removing parameters
BCDTOASC ENDP
;********************************************************************
; 把ASCII码转化为非压缩的BCD码
;********************************************************************
ASCTONOBCD PROC NEAR32
push ebp
mov ecx , 0
mov ebx , esi
whileDigit1: ;Judge char is 0 to 9
cmp byte ptr [esi] , '0'
jl EndWhileDigitD1
cmp byte ptr [esi] , '9'
jg EndWhileDigitD1
inc ecx
inc esi
jmp whileDigit1
EndWhileDigitD1:
mov esi , ebx
mov DWORD ptr count ,ecx
loopFor1: ;high 4 bit byte clear zero
mov al , [esi]
and al , 0fh
mov [edi] , al
inc edi
inc esi
loop loopFor1
pop ebp
ret
ASCTONOBCD ENDP
;********************************************************************
; 把非压缩的BCD码转化为ASCII码
;********************************************************************
NOBCDTOASC PROC NEAR32
push ebp
loopFor2: ;high 4 bit byte set 0011
mov al , [esi]
or al , 30h
mov [edi] , al
inc edi
inc esi
loop loopFor2
pop ebp
ret
NOBCDTOASC ENDP
;********************************************************************
; 一个字节非压缩BCD乘以多位字节非压缩BCD
;********************************************************************
SingleMulipic PROC NEAR32
push ebp
push esi
push ecx
push edx
lea esi , nobcd1
lea edi , Median1
add esi , edx
add edi , 21
mov bh , 0
mov ecx , edx
mov edx , count
mov count1 , edx
whileNoZero:
cmp count1 , 0h
je loopFor3
dec edi
mov BYTE PTR[edi], 0
dec count1
jmp whileNoZero
loopFor3:
dec esi ; point at operand byte to left
dec edi ; and at destination byte
mov al, [esi] ; digit from 8 byte number
mul bl ; multiply by single byte
aam ; adjust to unpacked BCD
add al, bh ; add lastCarry
aaa ; adjust to unpacked BCD
mov [edi], al ; store units digit
mov bh, ah ; store lastCarry
loop loopFor3
dec edi
cmp bh , 0
je Round
mov [edi], bh
Round:
lea esi , Median1
lea edi , Median2
call addUnp
pop edx
pop ecx
pop esi
pop ebp
ret
SingleMulipic ENDP
;********************************************************************
; 把压缩的BCD码加法函数
;********************************************************************
addUnp PROC NEAR32
; add two unpacked BCD numbers
; parameter 1: operand1 and destination address
; parameter 2: operand2 address
; author: R. Detmer revised: 5/98
push ebp
add esi, 21 ; point at byte after source
add edi, 21 ; byte after destination
clc ; clear carry flag
mov ecx, 21 ; count of bytes to process
forAdd: dec edi ; point at operand bytes to left
dec esi
mov al, [edi] ; get one operand byte
adc al, [esi] ; add other operand byte
aaa ; adjust to unpacked BCD
mov [edi], al ; save sum
loop forAdd ; repeat for all 8 bytes
pop ebp
ret ; return, discarding paramters
addUnp ENDP
;********************************************************************
; 把压缩的BCD码减法函数
;********************************************************************
subUnp PROC NEAR32
push ebp
clc ; clear carry flag
forSub: dec edi ; point at operand bytes to left
dec esi
mov al, [edi] ; get one operand byte
sbb al, [esi] ; add other operand byte
aas ; adjust to unpacked BCD
mov [edi], al ; save sum
loop forSub ; repeat for all 8 bytes
pop ebp
ret ; return, discarding paramters
subUnp ENDP
;********************************************************************
; 判断两数大小函数,如果大于等于al=0 , 否则al=-1
;********************************************************************
ifNegative PROC NEAR32
push ebp
push esi
push edi
clc ; clear carry flag
forSub: dec edi ; point at operand bytes to left
dec esi
mov al, [edi] ; get one operand byte
sbb al, [esi] ; add other operand byte
aas ; adjust to unpacked BCD
loop forSub ; repeat for all 8 bytes
jnc Positive
mov al , 01h
jmp exit1
Positive:
mov al , 0h
exit1:
pop edi
pop esi
pop ebp
ret
ifNegative ENDP
;********************************************************************
; 当除数大于被除数时,输出余数为被除数,商为0
;********************************************************************
DivMorediv PROC NEAR32
push ebp
lea edi , lastRemainder
lea esi , nobcd1
mov ecx , count1
loopFor9:
mov al , BYTE PTR [esi]
mov BYTE PTR [edi] , al
inc esi
inc edi
loop loopFor9
lea esi , Quotient1
lea edi , Quotient
mov ecx , 1
call NOBCDTOASC
output label4
output Quotient
mov edx , count1
lea esi , lastRemainder
lea edi , result
mov ecx , count1
call NOBCDTOASC
output label5
output result
pop ebp
ret
DivMorediv ENDP
;********************************************************************
; 把未压缩的BCD码乘法
;********************************************************************
mulUnp1 PROC NEAR32
; multiply 8 byte and 1 byte unpacked BCD numbers
; parameter 1: destination address
; parameter 2: address of 8 byte unpacked BCD number
; parameter 3: word w/ low-order byte containing 1-digit BCD nbr
push ebp
push ecx
mov count4 , 0h
mov bh , 0h
mov ecx, count ; count of bytes to process
forMul: dec esi ; point at operand byte to left
dec edi ; and at destination byte
mov al, [esi] ; digit from 8 byte number
mul bl ; multiply by single byte
aam ; adjust to unpacked BCD
add al, bh ; add lastCarry
aaa ; adjust to unpacked BCD
mov [edi], al ; store units digit
mov bh, ah ; store lastCarry
loop forMul ; repeat for all 8 bytes
dec edi
mov [edi] , bh
cmp bh , 0
je exit
mov count4 , 1
exit: pop ecx
pop ebp
ret ; return, discarding paramters
mulUnp1 ENDP
;********************************************************************
; 在运算除法时,被减数与减数个数相等时函数
;********************************************************************
EqualNumbers PROC NEAR32
push ebp
pushad
mov ecx , count
lea esi , nobcd2
add esi , count
lea edi , Median2
add edi , 21
mov bl , 2h
call mulUnp1
lea edi , Median1
add edi , count
lea esi , Median2
add esi , 21
add ecx , count4
call ifNegative
cmp al , 0
je toJudge9
dec bl
call OutMedian2
jmp exit4
toJudge9: ;Divisor Mulipic 0 to 9 , made result <= Dividend and Dividend-result< Divisor
lea esi , nobcd2
add esi , count
lea edi , Median2
add edi , 15h
inc bl
cmp bl , 9h
je Nowhile8
call mulUnp1
lea esi , Median2
add esi , 21
lea edi , Median1
add edi ,count
mov ecx , count
add ecx , count4
call ifNegative
mov dl , al
mov ecx , count
lea esi , Median1
add esi , count
lea edi , Median2
add edi , 21
loopFor15:
dec edi
dec esi
mov al , [esi]
cmp BYTE PTR[edi] , al
jne Nowhile2
loop loopFor15
jmp Nowhile8
Nowhile2:
cmp dl , 0
je toJudge9
dec bl
Nowhile8:
cmp bl , 9
jne Equal9
lea esi , nobcd2
add esi , count
lea edi , Median2
add edi , 21
call mulUnp1
mov ecx , count
lea esi , Median1
lea edi , Median2
add edi , 21
sub edi , ecx
loopFor16:
mov al , [esi]
cmp al , BYTE PTR[edi]
jl Less9
inc edi
inc esi
loop loopFor16
jmp Equal9
Less9: dec esi
dec edi
mov al , [esi]
cmp al , BYTE PTR[edi]
jg Equal9
dec bl
Equal9: call OutMedian2 ; do Quotient and Remainder
exit4:
popad
pop ebp
ret
EqualNumbers ENDP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -