Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Applied links to System Call Reference API's

The Z88 provides multiplication and division routines for 16 and 24 bit binary numbers as well as routines to convert between binary values and decimal numbers represented by ASCII digits. The arithmetic routines use the HL and DE registers (BHL and CDE for 24 bits) as input parameters with the result in HL (or BHL). In the case of division DE (or CDE) returns the remainder. The only error that is flagged is division by zero; Fc = 0 and A = RC_FAIL ($16). No overflow error is provided in the case of multiplication, so it is up to the user of these routines to check for overflow, if necessary.

GN_

...

M16      unsigned

...

16bit

...

multiplication
GN_

...

D16      unsigned

...

16bit

...

division
GN_

...

M24      unsigned

...

24bit

...

multiplication
GN_

...

D24      unsigned

...

24bit

...

division

The conversion routines are quite flexible with the ASCII source or destination being either in memory, at a stream or at a filter. The binary source or destination can either be the BC register pair (16 bits) or a 4 byte buffer in memory (32 bits). When converting from binary to ASCII you have four formatting options. Bits 4 to 7 of the Accumulator (A) define the width of the output field (where zero means as large as is necessary). Bits 1 and 2 of A are set to output a space before and after the decimal digits respectively. If bit 0 of A is set then instead of generating spaces in order to push the number to the right hand edge of the numeric field, zero digits are generated instead.

GN_

...

Gdn      convert

...

ASCII

...

string

...

to

...

binary

...

number
GN_

...

Pdn      convert

...

binary

...

integer

...

to

...

an

...

ASCII

...

string

Example 

We now take an opportunity to present a more substantial example than before. The following code fragment accepts a number from the keyboard, converts it to binary, multiplies it by 10, converts back to ASCII decimal and finally outputs it to the screen. Included in this fragment is the memory allocation necessary to obtain an input buffer for the input line routine. Note that some static workspace has to be used here, to store the memory pool handle. This is because an error handler will need to be able to access this handle to close off the memory pool. An error handler associated with this piece of code needs to fetch the memory handle from static workspace and close the memory pool before exciting the application.

...