flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > adding a carry

Author
Thread Post new topic Reply to topic
FoXx



Joined: 25 Feb 2025
Posts: 20
FoXx 06 Oct 2025, 10:25
Code:
SCALE_SIZE = 1024
VOLUME = 100000

struct FLOAT64

        high    dd ?
        low     dd ?
        under   dd ?
ends


        mov ESI, [lpSinusScale]
        mov EBX, VOLUME
        mov ECX, SCALE_SIZE

        mov EDI, val
        xor EAX, EAX
        stosd
        stosd
        stosd

.integrator:
        lodsd
        mul EBX
        add [val.under],EAX
        adс [val.low],  EDX
        adc [val.high], 0

        loop .integrator    
I'm trying to integrate a 64-bit value into a 32-bit processor. Precise calculations are required. A solution already exists. I'm not very familiar with x86 instructions.
Is there a way to add a carry without adding a third value?
Code:
        add [val.under],EAX
        adс [val.low],  EDX
        adz [val.high]          ;       similar    


Last edited by FoXx on 06 Oct 2025, 13:37; edited 1 time in total
Post 06 Oct 2025, 10:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20739
Location: In your JS exploiting you and your system
revolution 06 Oct 2025, 11:21
Ideally the code should propagate the carry through all variables.
Code:
        add [val.under],EAX
        adc [val.low],  EDX ; use ADC here
        adc [val.high], 0   ; use ADC here also    
Post 06 Oct 2025, 11:21
View user's profile Send private message Visit poster's website Reply with quote
FoXx



Joined: 25 Feb 2025
Posts: 20
FoXx 06 Oct 2025, 13:37
You're right. It's figurative code. The order of the operators is wrong. I've fixed it.

Is there such an instruction for the х86 processor?
Post 06 Oct 2025, 13:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20739
Location: In your JS exploiting you and your system
revolution 06 Oct 2025, 21:12
There is no opcode ADZ.
Post 06 Oct 2025, 21:12
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.