LD HL,(BASIC2)
Fetch the VARPTR pointer from memory location 4274H and store it into Register Pair HL.
4E16
LD (VARPTR),HL
Store the VARPTR pointer into memory location 4EE1H.
4E19
LD HL,(BASIC1)
Fetch the NUMBER OF VARIABLES from memory location 4272H and store it into Register Pair HL.
4E1C
4E1F
LD (NUMB0),HL
LD (NUMB1),HL
Store the NUMBER OF VARIABLES into 4ED5H and 4EDFH.
LD DE,(NUMB1)
Fetch the NUMBER OF VARIABLES from 4EDFH and store it into Register Pair DE.
4E26
SRL E
Shift the contents of Register E right one bit position with bit 0 moved to the carry flag and a zero is put into bit 7, so 76543210[x] becomes 07654321[0].
4E28
XOR A
Set Register A to ZERO and clear all Flags.
4E29
SRL D
Shift the contents of Register D right one bit position with bit 0 moved to the carry flag and a zero is put into bit 7, so 76543210[x] becomes 07654321[0].
4E2B
If Bit 0 of Register D wasn't a 0, the NC FLAG will be set, so JUMP to 4E2FH.
4E2D
SET 7,E
If Bit 0 of Register D was a 0, SET (i.e., set as 1) BIT 7 of Register E (the one bit which was set to 0 via the SRL).
LD (NUMB1),DE
Store the modified/rotated NUMBER OF VARIABLES held in Register Pair DE into memory location 4EDFH.
4E33
4E33
LD A,D
OR E
Since the Z-80 cannot test Register Pair DE against zero, the common trick is to set Register A to equal to Register D, and then OR A against Register E. Only if both Register D and Register E were zero can the Z FLAG be set.
4E35
RET Z
If we were given 0 variables to sort, RETurn to the caller.
4E36
LD HL,(NUMB0)
Otherwise, fetch the original NUMBER OF VARIABLES from memory location 4ED5H and store it into Register Pair HL.
4E39
SBC HL,DE
Subtract the modified/shifted NUMBER OF VARIABLES (held in DE) from the original NUMBER OF VARIABLES (held in Register Pair HL).
4E3B
LD (LAB15),HL
Store that difference into memory location 4EDBH.
4E3E
LD HL,0000H
Let Register Pair HL equal 0000H.
4E41
LD (LAB14),HL
Store a 0000H into memory location 4ED9H.
LD HL,(LAB14)
Fetch the value held in memory location 4ED9H (which will be 0000H on a pass through) and store it into Register Pair HL.
4E47
LD (LAB13),HL
Store the value held in Register Pair HL (which will be 0000H on a pass through) into memory location 4ED7H.
LD HL,(LAB13)
Fetch the value held in memory location 4ED7H (which will be 0000H on a pass through) and store it into Register Pair HL.
4E4D
LD DE,(NUMB1)
Fetch the value held in memory location 4EDFH and store it into Register Pair DE.
4E51
ADD HL,DE
LET Register Pair HL = Register Pair HL + Register DE.
4E52
LD (LAB16),HL
Store the value held in Register Pair HL into memory location 4EDDH.
4E55
EX DE,HL
Let DE = HL. We don't care what was in DE at the time of this EXchange because HL will be overwritten.
The next few instructions set HL = DE * 3
4E56
LD HL,0000H
Let Register Pair HL equal 0000H.
4E59
ADD HL,DE
LET Register Pair HL = Register Pair HL + Register DE.
4E5A
ADD HL,DE
LET Register Pair HL = Register Pair HL + Register DE.
4E5B
ADD HL,DE
LET Register Pair HL = Register Pair HL + Register DE.
4E5C
PUSH HL
Save the contents of Register Pair HL to the top of the stack.
4E5D
LD DE,(LAB13)
Fetch the value held in memory location 4ED7H and store it into Register Pair DE.
The next few instructions set HL = DE * 3
4E61
LD HL,0000H
Let Register Pair HL equal 0000H.
4E64
ADD HL,DE
LET Register Pair HL = Register Pair HL + Register DE.
4E65
ADD HL,DE
LET Register Pair HL = Register Pair HL + Register DE.
4E66
ADD HL,DE
LET Register Pair HL = Register Pair HL + Register DE.
4E67
LD BC,(VARPTR)
Fetch the value held in memory location 4EE1H and store it into Register Pair BC.
4E6B
ADD HL,BC
LET Register Pair HL = Register Pair HL + Register BC.
4E6C
EX DE,HL
EXchange the value stored in Register Pair HL with the value stored in Register Pair DE.
4E6D
POP HL
Put the value held at the top of the STACK into Register Pair HL, and then remove the entry from the stack.
4E6E
ADD HL,BC
LET Register Pair HL = Register Pair HL + Register BC.
4E6F
PUSH HL
Save the contents of Register Pair HL to the top of the stack.
4E70
PUSH DE
Save the contents of Register Pair DE to the top of the stack.
4E71
LD C,00H
Let Register C equal 00H.
4E73
LD A,(HL)
Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register A.
4E74
LD B,A
Copy the contents of Register A into Register B.
4E75
LD A,(DE)
Fetch the value held in the memory location pointed to by Register Pair DE and store it into Register A.
4E76
CP B
Compare the value held in Register A against the value held in Register B. Results:
- If Register A equals the value held in Register B, the Z FLAG is set.
- If A < B/ 160/, the CARRY FLAG will be set.
- if A >= B/ 160/, the NO CARRY FLAG will be set.
4E77
If the NC FLAG (No Carry) has been set, JUMP to 4E7CH.
4E79
LD C,01H
Let Register C equal 01H.
4E7B
LD B,A
Copy the contents of Register A into Register B.
XOR A
Set Register A to ZERO and clear all Flags.
4E7D
OR B
OR Register B against Register A. The results are stored in Register A.
4E7E
If the Z FLAG (Zero) has been set, JUMP to 4E99H.
4E80
PUSH BC
Save the contents of Register Pair BC to the top of the stack.
4E81
INC DE
INCrement the value stored in Register Pair DE by 1.
4E82
INC HL
INCrement the value stored in Register Pair HL by 1.
4E83
LD C,(HL)
Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register C.
4E84
INC HL
INCrement the value stored in Register Pair HL by 1.
4E85
LD B,(HL)
Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register B.
4E86
PUSH BC
Save the contents of Register Pair BC to the top of the stack.
4E87
POP HL
Put the value held at the top of the STACK into Register Pair HL, and then remove the entry from the stack.
4E88
EX DE,HL
EXchange the value stored in Register Pair HL with the value stored in Register Pair DE.
4E89
LD C,(HL)
Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register C.
4E8A
INC HL
INCrement the value stored in Register Pair HL by 1.
4E8B
LD B,(HL)
Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register B.
4E8C
PUSH BC
Save the contents of Register Pair BC to the top of the stack.
4E8D
POP HL
Put the value held at the top of the STACK into Register Pair HL, and then remove the entry from the stack.
4E8E
POP BC
Put the value held at the top of the STACK into Register Pair BC, and then remove the entry from the stack.
LD A,(DE)
Top of a DJNZ loop. Fetch the value held in the memory location pointed to by Register Pair DE and store it into Register A.
4E90
SUB (HL)
LET Register A = Register A - Register Pair HL.
4E91
If the C FLAG (Carry) has been set, JUMP to 4E9DH.
4E93
If the NZ FLAG (Not Zero) has been set, JUMP to 4EBCH.
4E95
INC DE
INCrement the value stored in Register Pair DE by 1.
4E96
INC HL
INCrement the value stored in Register Pair HL by 1.
4E97
LOOP back to 4E8FH, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
BIT 0,C
Test Bit Number 0 of Register C. Z FLAG will be set if that bit is 0, and NZ FLAG will be set if that bit is 1.
4E9B
If the NZ FLAG (Not Zero) has been set, JUMP to 4EBCH.
POP DE
Put the value held at the top of the STACK into Register Pair DE, and then remove the entry from the stack.
4E9E
POP HL
Put the value held at the top of the STACK into Register Pair HL, and then remove the entry from the stack.
4E9F
LD B,03H
Let Register B equal 03H.
LD C,(HL)
Top of a DJNZ loop. Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register C.
4EA2
EX DE,HL
EXchange the value stored in Register Pair HL with the value stored in Register Pair DE.
4EA3
LD A,(HL)
Fetch the value held in the memory location pointed to by Register Pair HL and store it into Register A.
4EA4
LD (HL),C
Store the value held in Register C into the memory location pointed to by Register Pair HL.
4EA5
EX DE,HL
EXchange the value stored in Register Pair HL with the value stored in Register Pair DE.
4EA6
LD (HL),A
Store the value held in Register A into the memory location pointed to by Register Pair HL.
4EA7
INC HL
INCrement the value stored in Register Pair HL by 1.
4EA8
INC DE
INCrement the value stored in Register Pair DE by 1.
4EA9
LOOP back to 4EA1H, reducing Register B each time, and continue to LOOP until Register B has been reduced to ZERO, in which case, continue with the next instruction.
4EAB
LD DE,(NUMB1)
Fetch the value held in memory location 4EDFH and store it into Register Pair DE.
4EAF
LD HL,(LAB13)
Fetch the value held in memory location 4ED7H and store it into Register Pair HL.
4EB2
XOR A
Set Register A to ZERO and clear all Flags.
4EB3
SBC HL,DE
Subtracts the value stored in Register Pair DE and the carry flag from the value stored in Register Pair HL.
4EB5
LD (LAB13),HL
Store the value held in Register Pair HL into memory location 4ED7H.
4EB8
If the NC FLAG (No Carry) has been set, JUMP to 4E4AH.