# Help with floating point division asembler8086

Page 1 of 1

## 1 Replies - 840 Views - Last Post: 20 June 2017 - 01:15 AM

### #1 macbob

Reputation: 1
• Posts: 23
• Joined: 06-March 16

# Help with floating point division asembler8086

Posted 19 June 2017 - 11:11 AM

The problem consists in implementing the Floating point division with reestablishment of the remainder and shift right.

I have set
○ mx= 1111101 which is 125
○ my= 101 which is 5
○ therefor mz should be 25 or 11001

-mx should be devided by my using a floating point division algorithm showed below
-mx and my should be 8 bit currently using 16bit to reserve memory currently for right shift
-lets omit the ex and ey which are the exponents of mx and my respectively(set to 1)
•Now the question is that i don't even know what i am doing wrong in my algorithm implementation.
-mz should give the answer in binary of the division
Compliling the code:

The algorithm i am trying to implement is the following:
```•rem=|mx|-|my|
•check sign
•if +:
shift mz to left
add mz+=1 (1 will be shifted in mz's value)
shift right |my|
rem - |my|
•if -:
shift mz to left (0 will be shifted in mz's value)
rem + |my|
shift right |my|
rem - |my|

```

•Picture link on what i want to implement

•Similiar algorithm found on internet

How i did the algorithm implementation further full code is attached at bottom of post
```        shl ax,8
shl bx,8
mov cx,7 ;nr of bit in mz, needed for loop
;xor mx, 0  ;mx=0
;mx - |my|
sub ax, bx
pushf
pushf
shl mz, 1
popf
js negg
negg:
popf
NextBit:
jns Positiv
;---------------------if remNegative
shl mz,1  ;mz shift once left with val=0
add ax,bx ;rem = rem + |my|
shr bx,1
sub ax,bx ;rem = rem - |my|
jmp looping
;---------------------if remPositive
Positiv:
shl mz,1 ;mz shift once left with val=1
shr bx,1
sub ax,bx ;rem = rem - |my|

looping:
loop NextBit
;Check mz sign from stack to return

cmp mz, 0
jns checkSignFromStack
;|mz|shifted right 1 time
shr mz, 1

checkSignFromStack:
;restore flag, specificaly the sign flag
;and modify corespondingly to sign
popf
jns endDivision
neg mz ; transforms to CC
inc ez
endDivision:
ret
Division endp
```

-------------------------------------------------------------------------------------

Please tell me what i am doing wrong and guide me.
I attached the whole code just in case HERE!

-------------------------------------------------------------------------------------

This post has been edited by macbob: 19 June 2017 - 11:13 AM

Is This A Good Question/Topic? 0

## Replies To: Help with floating point division asembler8086

### #2 macbob

Reputation: 1
• Posts: 23
• Joined: 06-March 16

## Re: Help with floating point division asembler8086

Posted 20 June 2017 - 01:15 AM

never mind i found the problem
```--------------------------Division--------------------------
Division proc
;mx xor my (Sign flag)
mov ax, mx
xor ax, my
pushf   ;push flag to stack

;ez = ex - ey
mov ah, ex
sub ah, ey
mov ez, ah

;calc|my|
mov ax, my
;Highest bit check:
;AX==1: dx=0FFFFh
;else   dx=0000h
cwd
xor ax, dx
sub ax, dx ; ax=|my|
mov bx, ax ; bx=|my| <-this is important
;calc|mx|
mov ax, mx
;Highest bit check:
;AX==1: dx=0FFFFh
;else   dx=0000h
cwd
shl bx,8
xor ax, dx
sub ax, dx ; ax=|mx|
mov cx,9 ;nr of bit in mz, needed for loop
;xor mx, 0  ;mx=0
NextBit:
;neg bx
sub ax, bx
jns signPlus
call negRemainder
jmp looping
signPlus:
call posRemainder
looping:
loop NextBit
cmp mz, 0 ;Check mz sign to normalize
jns checkSignFromStack
shr mz, 1  ;|mz|shifted right 1 time
checkSignFromStack:
;restore the sign flag
popf
jns endDivision
neg mz ; transforms to CC
inc ez
endDivision:
ret
Division endp
;--------------------Remainder computation--------------------
negRemainder proc
shl mz,1
shr bx,1
ret
negRemainder endp
;--------------------------
posRemainder proc
shl mz,1
shr bx,1
ret
posRemainder endp

;-------------------------------------------------------------
```