(C) Maximum / INTEGER
LONG??? What is it?
So long numbers are indicated on the
PC and AMIGA. Ie a number lying in
range from 0 to 4294967295, which is given for the submission
of four (4) byte of memory.
In this article I will teach you how to operate with such
numbers. And for what it is do you want? For example, you write
a game in which there are options such as money, gold and
etc. As usual, the money in these games
is much larger than 65535. Here
here is something just and useful LONG tsiferki ...
So, we have the number 12. 000. 00.
In Long, it looks like this: # 00B71B00
In the same assembly is to recruit as follows:
long_num DW # 00B7, # 1B00
The format of the job of every Long:
...
LD HL, # 00B7
EXX
LD HL, # 1B00
...
Ie in the highest part of HL, and
HL 'its lowest part.
Addition of two Long numbers
You just need to add lower part,
and then taking into account the C flag folded and older:
L_ADD
ADD HL, DE
EXX
ADC HL, DE
EXX
RET
At the entrance of the procedure: HL and HL '-
the first number in the DE and DE '- the second number.
At the exit: HL and HL 'the sum of two numbers.
The difference of two numbers Long
Here, roughly the same:
L_SUB
AND A
SBC HL, DE
EXX
SBC HL, DE
RET
The parameters are the same as L_ADD.
Print Long numbers
To print the numbers we need to translate from Long to
ASCII codes, which makes the following procedure:
L_PR LD IX, L_TAB; see below
LD A, 10, the number of 10 characters
L_PR0 EX AF, AF '
EXX
LD E, (IX +0); st.slovo Table.
LD D, (IX +1)
EXX
LD E, (IX +2); ml.slovo Table.
LD D, (IX +3)
LD A, '0 '-1
L_PR1 CALL L_SUB; count down until
INC A; enable the flag C
JR NC, L_PR1;
CALL L_ADD; restore the number of
LD (BC), A; in its buffer
INC BC
INC IX
INC IX
INC IX
INC IX
EX AF, AF '
DEC A
JR NZ, L_PR0; all the numbers
RET; ...
; Table of numbers:
L_TAB DW # 3B9A, # CA00; 1000000000
DW # 05F5, # E100; 100000000
DW # 0098, # 9680; 10000000
DW # 000F, # 4240, 1000000
DW # 0001, # 86A0; 100000
DW # 0000, # 2710, 10000
DW # 0000, # 03E8; 1000
DW # 0000, # 0064, 100
DW # 0000, # 000A; 10
DW # 0000, # 0001, 1
Before calling in the HL and HL 'number, and in
BC buffer address for the number. Example:
ORG # 6000
LD HL, # FFFF
EXX
LD HL, # FFFF
LD BC, BUFF
CALL L_PR
CALL 3435
LD A, 2
CALL 5633
LD HL, BUFF
LD B, 10
LOOP LD A, (HL)
RST 1916
INC HL
DJNZ LOOP
RET
BUFF DS 10
Entering Long numbers.
Or rather not enter, and the transformation of
of ASCII codes in Long format. Apply
This can be as follows:
...
LD HL, BUFF
...
CALL INPUT; Enter the number of
LD HL, BUFF
CALL L_DC
...
At the entrance of the procedure: HL-address buffer
where the number of sitting:
BUFF DB "212042067"
DB 0, ie, the end marker
; Code "" 0 ">" 9 "
After calling in the HL and HL 'is a number.
L_DC PUSH HL
LD B, 0
L_DC1 LD A, (HL); calculate how much
CP "0"; tsiferok from our
JR C, L_DC2; number
CP "9" 1
JR NC, L_DC2
INC B
INC HL
JR L_DC1
L_DC2 EXX
POP BC; in BC it
LD HL, 0; Clear
EXX; new
LD HL, 0; number
EXX
L_DC3 LD A, B; all create one?
LD DE ,0-4
AND A
RET Z; Nooo!
EXX
DEC A; using the table
LD IX, L_TAB +36
JR Z, L_DC4; find
ADD IX, DE; desired
DEC A; us
JR Z, L_DC4; discharge
ADD IX, DE; number
DEC A
JR Z, L_DC4
ADD IX, DE
DEC A
JR Z, L_DC4
ADD IX, DE
DEC A
JR Z, L_DC4
ADD IX, DE
DEC A
JR Z, L_DC4
ADD IX, DE
DEC A
JR Z, L_DC4
ADD IX, DE
DEC A
JR Z, L_DC4
ADD IX, DE
DEC A
JR Z, L_DC4
ADD IX, DE
L_DC4 DEC B; aha, found
LD E, (IX); take what
LD D, (IX +1); we
EXX; add
LD E, (IX +2); to
LD D, (IX +3); a new number
LD A, (BC); what is your number?
INC BC
L_DC5 CP "0" until the "zero"
JR Z, L_DC3
CALL L_ADD; add the category of
DEC A
JR L_DC5
Well all I have given already many
information about Long, so that the use
Health ...
I hope that this article applies to someone
help. I also want to recall that such
numbers have already been successfully used over
Thank Mednonogov known in his UFO.
I'm more of such a method yet nowhere
met.
*