BDC - Binary Coded Decimal

26 views
Skip to first unread message

Bert Mariani

unread,
Aug 12, 2026, 11:03:24 AMAug 12
to The Ring Programming Language
Hello Mahmoud, Youssef et ALL

Intel Chips have BCD Binary Coded Decimal instructions in 32 Bit Mode.
Using 64 Bit mode the BCD instructions do not exist  ( Bad Intel) !!
Note: Banking does all their financial math using BCD on mainframes with Cobol.
Because floating point causes rounding errors. BCD is 100% accurate.

Attached:  bcd_add_msvc.c 
                   bcd_add.ring

The C-code runs even though my machine is 64 Bit
It uses the C to ASM instructions to operate ( see code)
It is currently coded to use upt o 40 BCD digits - a huge number.
I can run the bcd_add_msvc.exe on my 64 bit HP-I5
See below

I want to Use Ring and CFFI to run the  bcd_add_msvc.c   program.
Issues:  Ring-64 uses only DLL-64
               CFFI is installed under C:\Ring   ( 64)
               It needs to run in Ring-32

I downloaded a 2nd  --  C:\Ring-32\Ring 
I managed to install CFFI in C:\Ring-32\Ring
But run into problems. See errors below.
Is there a way to solve this mess ?

======================
32 BIT RING
cd Ring32\ring

-----
c:\Ring32\ring> C:\Ring32\ring\bin\ringpm.exe install ring-cffi from ysdragon
     Installing ring-cffi (master) ---> ring-cffi (1.0.0)
     Download Package Files For ring-cffi
      ------

c:\Ring32\ring>cd  c:\MyStuff\AA-BCD    // <<<===
c:\MyStuff\AA-BCD>C:\ring32\ring\bin\ring.exe BCD-Add.ring  // <<<===

Error (E9) : Can't open file cffi.ring
BCD-Add.ring Line (38) Error (C27) : Syntax Error!
BCD-Add.ring errors count : 1


c:\MyStuff\AA-BCD>

==========================
Working C
How to Compile and Run bcd_add_msvc.c 

Open "Developer Command Prompt for VS" from the Start menu
     **********************************************************************
     ** Visual Studio 2026 Developer Command Prompt v18.7.3
     ** Copyright (c) 2026 Microsoft Corporation
     **********************************************************************
C:\Program Files\Microsoft Visual Studio\18\Community>

cd c:\MyStuff\AA-BCD

c:\MyStuff\AA-BCD>cl /TC bcd_add_msvc.c
     Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36248 for x86
     Copyright (C) Microsoft Corporation.  All rights reserved.   
     bcd_add_msvc.c
     Microsoft (R) Incremental Linker Version 14.51.36248.0
     Copyright (C) Microsoft Corporation.  All rights reserved.   
     /out:bcd_add_msvc.exe
     bcd_add_msvc.obj

   //=========================
   // RUN
c:\MyStuff\AA-BCD>bcd_add_msvc.exe
Enter first number (up to 38 integer digits, 2 decimal places, e.g. 123.45): 123123123123123.98
Enter second number (up to 38 integer digits, 2 decimal places, e.g. 123.45): 345345345345345.07

Input 1 ->  BCD: 123123123123123.98
Input 2 ->  BCD: 345345345345345.07
Sum     ->  BCD: 468468468468469.05

c:\MyStuff\AA-BCD>
================================
 
Thanks
Bert Mariani



bcd_add_msvc.c
BCD-Add.ring

Mahmoud Fayed

unread,
Aug 13, 2026, 7:40:26 AMAug 13
to The Ring Programming Language
Hello Bert

Thanks for sharing the code :D

Keep up the GREAT WORK :D

Greetings,
Mahmoud
Reply all
Reply to author
Forward
0 new messages