Math Processor Unit Library

libmpu – library of arithmetic functions for integer, real, and complex numbers of increased digit capacity

16 Commits   0 Branches   2 Tags   |
07a2b481 (kx 2024-12-28 08:20:38 +0300   1) .\" Copyright 2024 Andrew V.Kosteltsev (kx@radix-linux.su)
07a2b481 (kx 2024-12-28 08:20:38 +0300   2) .\"
07a2b481 (kx 2024-12-28 08:20:38 +0300   3) .\"
07a2b481 (kx 2024-12-28 08:20:38 +0300   4) .TH isbb 3  "December 27, 2024" "libmpu" "LibMPU Programmer's Manual"
07a2b481 (kx 2024-12-28 08:20:38 +0300   5) .SH NAME
07a2b481 (kx 2024-12-28 08:20:38 +0300   6) \fBisbb\fP \- subtraction signed and unsigned with carryover
07a2b481 (kx 2024-12-28 08:20:38 +0300   7) .SH SYNOPSIS
07a2b481 (kx 2024-12-28 08:20:38 +0300   8) .nf
07a2b481 (kx 2024-12-28 08:20:38 +0300   9) .B #include <libmpu.h>
07a2b481 (kx 2024-12-28 08:20:38 +0300  10) .PP
07a2b481 (kx 2024-12-28 08:20:38 +0300  11) .BI "void isbb( mpu_int *" c ", mpu_int *" a ", mpu_int *" b ", int " nb " );
07a2b481 (kx 2024-12-28 08:20:38 +0300  12) .fi
07a2b481 (kx 2024-12-28 08:20:38 +0300  13) .SH DESCRIPTION
07a2b481 (kx 2024-12-28 08:20:38 +0300  14) The \fBisbb()\fP function performs the operation of subtraction of integers located at addresses \fBa\fP
07a2b481 (kx 2024-12-28 08:20:38 +0300  15) and \fBb\fP, subtracts the value of the carry flag \fBC\fP from the obtained difference and places the
07a2b481 (kx 2024-12-28 08:20:38 +0300  16) result at address \fBc\fP. The operands can be numbers with or without a sign. The memory contents at
07a2b481 (kx 2024-12-28 08:20:38 +0300  17) addresses \fBa\fP, \fBb\fP are not changed, the previous memory contents at address \fBc\fP are lost.
07a2b481 (kx 2024-12-28 08:20:38 +0300  18) The \fBnb\fP parameter determines the size, in bytes, of the operands located at addresses
07a2b481 (kx 2024-12-28 08:20:38 +0300  19) \fBc\fP, \fBa\fP, \fBb\fP. Since the \fBisbb()\fP function uses the \fBC\fP carry flag,
07a2b481 (kx 2024-12-28 08:20:38 +0300  20) it can be used to subtract numbers whose length exceeds the maximum allowed size of integers.
07a2b481 (kx 2024-12-28 08:20:38 +0300  21) .PP
07a2b481 (kx 2024-12-28 08:20:38 +0300  22) The function affects the flags \fBA\fP, \fBC\fP, \fBO\fP, \fBP\fP, \fBS\fP, \fBZ\fP, and \fBV\fP.
07a2b481 (kx 2024-12-28 08:20:38 +0300  23) .PP
07a2b481 (kx 2024-12-28 08:20:38 +0300  24) Flags \fBА\fP and \fBP\fP are set only when the size of operands \fBa\fP, \fBb\fP is one or
07a2b481 (kx 2024-12-28 08:20:38 +0300  25) two bytes (\fBnb\fP == 1 || \fBnb\fP == 2).
07a2b481 (kx 2024-12-28 08:20:38 +0300  26) .sp
07a2b481 (kx 2024-12-28 08:20:38 +0300  27) .SH EXAMPLES
07a2b481 (kx 2024-12-28 08:20:38 +0300  28) .nf
07a2b481 (kx 2024-12-28 08:20:38 +0300  29) .sp
07a2b481 (kx 2024-12-28 08:20:38 +0300  30) #include <libmpu.h>
07a2b481 (kx 2024-12-28 08:20:38 +0300  31) #include <stdio.h>
07a2b481 (kx 2024-12-28 08:20:38 +0300  32) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  33) int main( void )
07a2b481 (kx 2024-12-28 08:20:38 +0300  34) {
07a2b481 (kx 2024-12-28 08:20:38 +0300  35)   int  rc = 0;
07a2b481 (kx 2024-12-28 08:20:38 +0300  36) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  37)   __mpu_init();
07a2b481 (kx 2024-12-28 08:20:38 +0300  38)   __mpu_extra_warnings = 1;
07a2b481 (kx 2024-12-28 08:20:38 +0300  39) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  40)   {
07a2b481 (kx 2024-12-28 08:20:38 +0300  41)     mpu_int128_t   c, a, b;
07a2b481 (kx 2024-12-28 08:20:38 +0300  42)     int            nb = NB_I128;
07a2b481 (kx 2024-12-28 08:20:38 +0300  43)     __mpu_char8_t  s[256];
07a2b481 (kx 2024-12-28 08:20:38 +0300  44) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  45)     iatoi( a, "237", nb ); /* evaluate the A variable */
07a2b481 (kx 2024-12-28 08:20:38 +0300  46)     iatoi( b,  "37", nb ); /* evaluate the B variable */
07a2b481 (kx 2024-12-28 08:20:38 +0300  47) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  48)     __mpu_stc(); /* Set Carry Flag */
07a2b481 (kx 2024-12-28 08:20:38 +0300  49) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  50)     isbb( c, a, b, nb );
07a2b481 (kx 2024-12-28 08:20:38 +0300  51)     iitoa( s, c, RADIX_DEC, LOWERCASE, nb ); /* convert C value to ASCII string S */
e3f8685d (kx 2024-12-30 18:22:24 +0300  52)     printf( "c = %s;\\n", s ); /* c = 199; */
07a2b481 (kx 2024-12-28 08:20:38 +0300  53)   }
07a2b481 (kx 2024-12-28 08:20:38 +0300  54) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  55)   __mpu_free_context();
07a2b481 (kx 2024-12-28 08:20:38 +0300  56) 
07a2b481 (kx 2024-12-28 08:20:38 +0300  57)   return( rc );
07a2b481 (kx 2024-12-28 08:20:38 +0300  58) }
07a2b481 (kx 2024-12-28 08:20:38 +0300  59) .fi
07a2b481 (kx 2024-12-28 08:20:38 +0300  60) .sp
07a2b481 (kx 2024-12-28 08:20:38 +0300  61) .SH SEE ALSO
07a2b481 (kx 2024-12-28 08:20:38 +0300  62) .BR iadd(3),
41c271da (kx 2025-01-05 15:42:39 +0300  63) .BR isub(3),
07a2b481 (kx 2024-12-28 08:20:38 +0300  64) .BR iadc(3),
41c271da (kx 2025-01-05 15:42:39 +0300  65) .BR ishl(3),
41c271da (kx 2025-01-05 15:42:39 +0300  66) .BR ishr(3),
41c271da (kx 2025-01-05 15:42:39 +0300  67) .BR isal(3),
41c271da (kx 2025-01-05 15:42:39 +0300  68) .BR isar(3),
41c271da (kx 2025-01-05 15:42:39 +0300  69) .BR irol(3),
41c271da (kx 2025-01-05 15:42:39 +0300  70) .BR iror(3),
41c271da (kx 2025-01-05 15:42:39 +0300  71) .BR ircl(3),
41c271da (kx 2025-01-05 15:42:39 +0300  72) .BR ircr(3),
41c271da (kx 2025-01-05 15:42:39 +0300  73) .BR ishln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  74) .BR ishrn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  75) .BR isaln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  76) .BR isarn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  77) .BR iroln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  78) .BR irorn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  79) .BR ircln(3),
41c271da (kx 2025-01-05 15:42:39 +0300  80) .BR ircrn(3),
41c271da (kx 2025-01-05 15:42:39 +0300  81) .BR ineg(3),
41c271da (kx 2025-01-05 15:42:39 +0300  82) .BR inot(3),
41c271da (kx 2025-01-05 15:42:39 +0300  83) .BR iand(3),
41c271da (kx 2025-01-05 15:42:39 +0300  84) .BR itest(3),
41c271da (kx 2025-01-05 15:42:39 +0300  85) .BR icmp(3),
41c271da (kx 2025-01-05 15:42:39 +0300  86) .BR ior(3),
41c271da (kx 2025-01-05 15:42:39 +0300  87) .BR ixor(3),
41c271da (kx 2025-01-05 15:42:39 +0300  88) .BR iinc(3),
41c271da (kx 2025-01-05 15:42:39 +0300  89) .BR idec(3),
41c271da (kx 2025-01-05 15:42:39 +0300  90) .BR ixchg(3),
41c271da (kx 2025-01-05 15:42:39 +0300  91) .BR icpy(3),
41c271da (kx 2025-01-05 15:42:39 +0300  92) .BR icvt(3),
41c271da (kx 2025-01-05 15:42:39 +0300  93) .BR imul(3),
41c271da (kx 2025-01-05 15:42:39 +0300  94) .BR ismul(3),
41c271da (kx 2025-01-05 15:42:39 +0300  95) .BR idiv(3),
41c271da (kx 2025-01-05 15:42:39 +0300  96) .BR isdiv(3),
41c271da (kx 2025-01-05 15:42:39 +0300  97) .BR iatoi(3),
41c271da (kx 2025-01-05 15:42:39 +0300  98) .BR iatoui(3),
41c271da (kx 2025-01-05 15:42:39 +0300  99) .BR iitoa(3),
41c271da (kx 2025-01-05 15:42:39 +0300 100) .BR iuitoa(3).