Article View: alt.msdos.programmer
Article #8508-Byte integer arithmetics: SUMMARY
From: Zhenja
Date: Sun, 20 Dec 1992 14:31
Date: Sun, 20 Dec 1992 14:31
111 lines
4762 bytes
4762 bytes
My original posting was: >Could somebody help with code/reference to solve the following problem: > >I need to realize 8-Byte integer arithmetics on a 808x6. >a) Add/sub two 8-Byte integers (signed at least); >b) Mul/div two 4-Byte integers to give one 8-Byte. >Actually, I have a 386 machine, so if it makes any difference I'd be happy >with 386-specific code, provided it couldd be assembled by TASM 2.0 and/or >understood by built-in assembler in TP 6.0 (or BC++ 2.0). > >I am familiar with 8086 assembler, and can (in principle) do it myself, but >as long as I am not a professional, it will take at least 3-5 days to debug >it properly. >I realize that this problem is homework for the 1st year in CS, so >references to widely known books (with answers!!) published before '92 >will do. Pieces of code would have saved a lot of time, however. >There is big-integer arithmetic in 8x7, but the idea is to avoid >co-processor to gain speed. > >Please answer to me directly. If I receive requests for summary, >I'll prepare and publish it. >Thanks in advance, >Sorokin Zhenya. First, I wish to thank everybody, who spent the time answering my silly (as it proved to be) question. The most detailed answer (a ready-to-use code, see below) came from Scott C. Sadow <scott%mycro.UUCP@mathcs.emory.edu>. My special thanks to him! Since the solution is just a straight-forward extension of 4-byte arithmetics of 8086, no comments are needed. Unfortunately, TP 6.0 and BC++ 2.0 reject any attempt to address extended registers using "asm" directives within a program and the user have to assemble an object file separately. More interesting to me was to evaluate if there is any speed difference between 8-byte arithmetics in processor itself and with the use of a built-in 8-byte "integer" arithmetics in a math coprocessor. A cycle with some 600000 repetitions was used to perform one-two single operations in both modes using TP 6.0. The results for 486DX-2, 50 MHz, 64K cache: 1. The time is mostly spent on pushing parameters, calling and cycling. 2. The use of math coprocessor is NOT SLOWER (and even faster in complex expressions, which do not require storage of intermediate results)! Only in operations like DIV and MOD the results of direct calculations are better within a factor of 1.5 but the speed difference due to different modes of parameter pushing is still higher. These results may not be necessarily valid for 386/387 combination, where some motherboard-specific features can occur. Merry X-mas and Happy New Year to everybody! Frohe Weihnachten und guten Rutsch im Neuen Jahr! The code below is a courtesy of Scott C. Sadow <scott%mycro.UUCP@mathcs.emory.edu> Scott writes: Here is some example 80386 I put together (assembles with TASM): --------------------------------------- .386 ideal jumps model tiny codeseg ASSUME DS:NOTHING Start: ;8 byte add - Num1 + Num2 = Result MOV EAX,[dword Num1+0] ;handle lower 4 bytes ADD EAX,[dword Num2+0] MOV [dword Result+0],EAX MOV EAX,[dword Num1+4] ;handle upper 4 bytes ADC EAX,[dword Num2+4] MOV [dword Result+4],EAX ;8 byte subtract - Num1 - Num2 = Result MOV EAX,[dword Num1+0] ;handle lower 4 bytes SUB EAX,[dword Num2+0] MOV [dword Result+0],EAX MOV EAX,[dword Num1+4] ;handle upper 4 bytes SBB EAX,[dword Num2+4] MOV [dword Result+4],EAX ;multiply - input is 2 4-byte number, output is 1 8-byte number MOV EAX,[dword Num1] MOV EDX,[dword Num2] MUL EDX ;result is in EDX:EAX ;divide - input is 2 4-byte numbers, output is 1 4-byte quotient and ; 1 4-byte remainder MOV EAX,[dword Num1] CDQ MOV EBX,[dword Num2] DIV EBX ;EAX = quotient, EDX = remainder ;divide - input is 1 8-byte number and 1 4-byte number, ; output is 1 4-byte quotient and 1 4-byte remainder MOV EAX,[dword Num1] MOV EDX,[dword Num1+4] MOV EBX,[dword Num2] DIV EBX ;EAX = quotient, EDX = remainder MOV AH,4CH INT 21H Num1 db 1,2,3,4,5,6,7,8 Num2 db 1,2,3,4,5,6,7,8 Result db 0,0,0,0,0,0,0,0 end Start --------------------------------------- Scott C. Sadow scott@mycro.UUCP ...gatech!nanovx!mycro!scott --------------------------- Sorokin Zhenya. Vienna, Austria.
Technical Details
Message-ID:
<sorokin.26@ps1.iaee.tuwien.ac.at>Path:
arc1-ca.pugleaf.net!sparky!uunet!email!ps1.iaee.tuwien.ac.at!sorokinShow Full Headers
Complete Article Headers
Newsgroups: alt.msdos.programmer,alt.lang.asm,comp.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!email!ps1.iaee.tuwien.ac.at!sorokin From: sorokin@ps1.iaee.tuwien.ac.at (Zhenja) Subject: 8-Byte integer arithmetics: SUMMARY Message-ID: <sorokin.26@ps1.iaee.tuwien.ac.at> Sender: news@email.tuwien.ac.at Nntp-Posting-Host: pc77.iaee.tuwien.ac.at Organization: Inst. for General Electrics & Electronics, TU Vienna Date: Sun, 20 Dec 1992 14:31:57 GMT Lines: 111