659 questions
2
votes
1
answer
173
views
Is it possible to call x86 `idiv r/m8` from MSVC2022 using C++ directly?
I am trying to call idiv r/m8 using MSVC2022's current Microsoft Visual C++ Compiler 17.4.33403.182 and C++.
Using the most straightforward approach:
struct cdiv_t
{
// char
std::int8_t quot;
...
6
votes
1
answer
260
views
Speeding up integer division with doubles
I have a fixed-point math-heavy project and I was looking to speed up integer divisions. I tested double division with SSE4 and AVX2 and got nearly 2x speedup versus scalar integer division. I wonder ...
2
votes
0
answers
50
views
record accumulate round error for integer divisions to reduce final error
It is well-known that integer division can result in errors, no matter which rounding method is used (we use Floor rounding below as example).
Moreover, if division is calculated multiple times (with ...
0
votes
0
answers
140
views
Question about Knuth's Algorithm D for division
I want to implement Knuth's Algorithm D for division on C (Link to Knuth's book, p272). In step "D4. [Multiply and subtract.]", it states:
if the result of this step is actually negative, (...
1
vote
1
answer
123
views
Bug in the normalization step of Knuth Algorithm D (TAOCP 4.3.1)?
Knuth Algorithm D, during the normalization step (D1), states to set d to (b-1)//v_hi where b is the basis (word size or half-word size) and v_hi is the upper limb of the denominator. Then multiply ...
1
vote
1
answer
59
views
Overflow error in VBA calculation (division)
In the macro below I get an Overflow error when calculating Rate = cell.Offset(0, 7).Value / cell.Offset(0, 2).Value - regardless of whether Rate is declared as Long or Double. Kindly help to identify ...
1
vote
0
answers
44
views
Why is floor division inconsistent with division follow by floor, e.g. 1//0.2 = 4.0 [duplicate]
The operator // for integer division is called "floor division" in the python documentation, but comparing to other floor implementations there is a discrepancy, for example:
>>> ...
1
vote
1
answer
1k
views
Restoring division algorithm in Risc V
I wanted to implement the restoring division algorithm (without using the div operation) in RISCV assembly language.
The algorithm I have to implement is the following
.
I implemented this, but it is ...
4
votes
1
answer
234
views
Optimized 53->32 bit modulo computation on 32-bit processors
This question arose when I looked into the efficient implementation of the MRG32k3a PRNG on 32-bit processors without, or slow, support for double computation. I am particularly interested in ARM, ...
0
votes
3
answers
290
views
How to return integer part using backslash when dividing two decimals in Visual Basic
I am trying to divide two decimals and want to get the exact integer part of the result only using a\b. Consider the following example:
Dim a, b As Integer
a = 200
b = 2
...
1
vote
2
answers
69
views
Division produces unexpected results [duplicate]
id client_id driver_id city_id status request_at
1 1 10 1 completed 2023-12-23
2 2 11 1 cancelled_by_driver 2023-12-23
3 3 12 6 completed 2023-12-23
4 4 13 6 ...
1
vote
1
answer
303
views
Catching / disabling SIGFPE exceptions from assembly
I get a SIGFPE exception when dividing by 0 in x86 assembly using idiv. How would I disable it from assembly? Do I need a syscall or can it be done directly in x86?
Reproduction:
test.asm
default rel
...
1
vote
1
answer
71
views
How to convert a binary number into decimal and show the answer in 3 digits?
I have this piece of code from my project. It is taking all the amount from the transaction and adding it and showing how much you earned in the day. The problem is it's not showing in decimal format ...
0
votes
2
answers
376
views
Nextion: Calculate inverse tan (arctan) without trig functions or floating point
I am programming an interface on this Nextion display. Specifically, I am trying to program a digital dial that rotates around a centre point.
These screens are great, but they don’t have any trig ...
1
vote
1
answer
831
views
Convert HEX to decimal in assembly 8086
I am trying to create a code which would take as input 1 8-bit number in HEX form and produce the decimal equivalent.
Here is my code:
data segment
msg1 db 10,13, "Give me a valid hex ...
0
votes
0
answers
5k
views
Restoring division algorithm for signed numbers
I am trying to follow the division algorithm for signed numbers (2's complement representation) based on the algorithm described here. This is the standard restoring method with M and AQ registers ...
1
vote
1
answer
373
views
uint64_t: Division with rounding
I'm trying to create a code which divides a uint64_t by another uint64_t plus it applies rounding to the result. The code should be as fast as possible and work for all inputs (e.g. I would prefer it ...
2
votes
1
answer
71
views
Do you convert signed integers to hex before doing an `idiv` in 64-bit Intel CPUs?
Suppose you want to divide -198077031546722079779 by 23 using gas. As this dividend is larger than %rax, how do you put it in %rdx:%rax? All the books I read on assembly avoid illustrating idiv with ...
3
votes
1
answer
102
views
Can the x87 perform exact division on UNsigned QUADword integers?
The 8086/8087/8088 MACRO ASSEMBLY LANGUAGE REFERENCE MANUAL (c) 1980 Intel Corporation mentions (Emphasis mine):
... the 8087 provides a very good approximation of the real number system. It is ...
0
votes
0
answers
158
views
Why isn't my IDIV instruction working as expected on Windows x64 using NASM assembler? [duplicate]
I tried using the below assembly code to get the quotient and remainder for IDIV instruction, but it didn't work as expected. I use NASM as the assembler.
It prints "The quotient is: -...
0
votes
4
answers
342
views
Make sure if a value in register is a multiple of 3 in AVR Studio using assembly
I want to make sure if a number in register is a multiple of 3 using AVR Studio and assembly language but on AVR ATmega 8515 so there is no div instruction/syntax
I already tried a couple method like ...
1
vote
1
answer
702
views
Powershell: Issues with 'Write-Progress"
I am making a script to backup databases in SSMS from Powershell. I want to add a progress bar since these databases take some time to backup. This is what I have. The progress bar is popping up but ...
-3
votes
1
answer
140
views
Assembly language Division (Problems is getting the remainder)
jmp start
mess1 db 'Enter 1st number: $'
mess2 db 0a,0d, 'Enter 2nd number: $'
nextline db 0a,0d, '$'
start:
mov ax, 03
int 10h
mov dx, offset mess1
call printstring
call input
...
0
votes
1
answer
253
views
Cortex M0+/GCC Division with Rounding
I'm trying to implement an integer division with rounding. Obviously, by default integer division does floor and I was thinking I could use the remainder to determine if I should add 1 to my result.
...
0
votes
3
answers
911
views
Dividing two numbers and printing the result and adding one to the result if there is a remainder, without using if-statements or imports or function? [duplicate]
I'm trying to divide number into groups in plain python without importing or the use of if-statements, and get the division into groups + remainder forming one extra group so that 200 / 99 would be 3, ...