0

So, i tried division two integer numbers, but in result i should get number with rounding to zero. If I do division 3/2, so result is 1, don't 2.

I used this site (code)

https://cs.fit.edu/~mmahoney/cse3101/float.html

Code in the end of this site don't work in my program.

global main
extern printf

section .data
str: db "%i", 10, 0
count: dq 3
size: dq 2
zero: dd 0x0C00
x: dw 0

section .text
main:
    mov ecx, 0

start:
    fninit
    fnstcw x
    mov ax, x
    or ax, c00h
    mov x, ax
    fldcw x

    fldcw dword [zero]

    fild qword [count]
    fidiv dword [size] 
    frndint
    fist dword [count]

    push dword [count]
    push dword str
    call printf 

mov eax, 1
int 80h

I read diferent book on this topical. I know i should do with register CR, but write code i can't. So, i use linux 86-bit. Please, help me... This writed me terminal (Errors)

test.asm:22: error: invalid combination of opcode and operands
test.asm:24: error: symbol `c00h' undefined
test.asm:25: error: invalid combination of opcode and operands
test.asm:26: error: invalid combination of opcode and operands
test.asm:28: error: mismatch in operand sizes

I tried using the normal "div" command but got an error. So, I searched the internet for a solution, but it doesn't work in my code. Perhaps this is somehow related to the type of OS and bit depth

OKIS
  • 55
  • 1
  • 7
  • Sorry for my crooked english :) – OKIS Jan 30 '21 at 19:38
  • If you want integer division with truncation toward 0, use `div`. `fidiv` does FP division, and `frndint` uses the current FP rounding mode (which you are changing, I guess to get the same result in a much more complex way). – Peter Cordes Jan 30 '21 at 19:41
  • @PeterCordesI tried this command, but get this "Floating point operation exception (memory dump made)" so for solution i use FPU – OKIS Jan 30 '21 at 19:48
  • 1
    If you'd searched on that, you'd have found [Why should EDX be 0 before using the DIV instruction?](https://stackoverflow.com/a/38416896) – Peter Cordes Jan 30 '21 at 19:53
  • @PeterCordes Yes, this is worked. Thank you. – OKIS Jan 30 '21 at 20:09

0 Answers0