Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PUBLIC LongDiv
- ; Longint division
- ; In DX:AX = 1st operand
- ; BX:CX = 2nd operand
- ; Out DX:AX = Result
- ; BX:CX = Remainder
- LongDiv:CMP Test8086,2
- JB @@0
- .386
- SHL EAX,16
- SHRD EAX,EDX,16
- SHL ECX,16
- SHRD ECX,EBX,16
- JE SHORT @@9a
- CDQ
- IDIV ECX
- MOV ECX,EDX
- SHLD EDX,EAX,16
- SHLD EBX,ECX,16
- RETF
- .8086
- @@0: PUSH BP
- XOR BP,BP
- OR DX,DX
- JNS @@1
- INC BP
- NEG AX
- ADC DX,0
- NEG DX
- @@1: OR BX,BX
- JE @@5
- JNS @@2
- INC BP
- INC BP
- NEG CX
- ADC BX,0
- NEG BX
- JE @@5a
- @@2: PUSH BP
- MOV SI,CX
- MOV DI,BX
- XOR BX,BX
- MOV CX,DX
- MOV DX,AX
- XOR AX,AX
- MOV BP,16
- @@3: SHL AX,1
- RCL DX,1
- RCL CX,1
- RCL BX,1
- INC AX
- SUB CX,SI
- SBB BX,DI
- JNC @@4
- DEC AX
- ADD CX,SI
- ADC BX,DI
- @@4: DEC BP
- JNE @@3
- POP BP
- JMP SHORT @@6
- @@9: POP BP
- @@9a: MOV AX,200
- JMP HaltError
- @@5: JCXZ @@9
- @@5a: XCHG AX,BX
- XCHG AX,DX
- DIV CX
- XCHG AX,BX
- DIV CX
- MOV CX,DX
- MOV DX,BX
- XOR BX,BX
- @@6: SHR BP,1
- JNC @@7
- NEG CX
- ADC BX,0
- NEG BX
- INC BP
- @@7: DEC BP
- JNE @@8
- NEG AX
- ADC DX,0
- NEG DX
- @@8: POP BP
- RETF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement