Hammer111
Junior Member level 3
Hi all
My university task is to make code that will sort(from smallest to largest) 10 data(numbers) from memory stored at adresses from 50H to 60H. I've been working on this for 5 hours and didn't succeeded.
I think my side of logic is good but somehow JP instruction is always done.
This is text representation of what did I(line by line):
I loaded HL register to adress 50H, then loaded accumulator A with data in memory at adress 50H, I increased HL register by one so it points to 51H, loaded register B with data at 51H. Put AND A to reset carry flag. Subtracted A-B regster, decreased HL register so it points to adress 50H.Loaded A again with data at 50H(because after subtraction register A was overwritten,but I got carry flag), increased HL (51H),
then
Exclamation this is where my program dies, line JP C, MEM should jump to MEM spot when carry flag is set to 1 but for me it always jumps (regardless of carry flag)Exclamation
at MEM:
load adress 51H with data at A register,decreased HL(50H) and load 50H with B register
Basicly at MEM I switched data from 50H to 51H and from 51H to 50H because subtraction showed carry flag.
Again, my problem is whether subtraction is positive or negative (carry flag set to 1 OR 0) I have execution of MEM subprogram.
Code:
LD HL,50H
LD A,(HL)
INC HL
LD B,(HL)
AND A
SBC A,B
DEC HL
LD A,(HL)
INC HL
JP C, MEM
MEM:
LD (HL),A
DEC HL
LD (HL),B
HALT
END
My university task is to make code that will sort(from smallest to largest) 10 data(numbers) from memory stored at adresses from 50H to 60H. I've been working on this for 5 hours and didn't succeeded.
I think my side of logic is good but somehow JP instruction is always done.
This is text representation of what did I(line by line):
I loaded HL register to adress 50H, then loaded accumulator A with data in memory at adress 50H, I increased HL register by one so it points to 51H, loaded register B with data at 51H. Put AND A to reset carry flag. Subtracted A-B regster, decreased HL register so it points to adress 50H.Loaded A again with data at 50H(because after subtraction register A was overwritten,but I got carry flag), increased HL (51H),
then
Exclamation this is where my program dies, line JP C, MEM should jump to MEM spot when carry flag is set to 1 but for me it always jumps (regardless of carry flag)Exclamation
at MEM:
load adress 51H with data at A register,decreased HL(50H) and load 50H with B register
Basicly at MEM I switched data from 50H to 51H and from 51H to 50H because subtraction showed carry flag.
Again, my problem is whether subtraction is positive or negative (carry flag set to 1 OR 0) I have execution of MEM subprogram.
Code:
LD HL,50H
LD A,(HL)
INC HL
LD B,(HL)
AND A
SBC A,B
DEC HL
LD A,(HL)
INC HL
JP C, MEM
MEM:
LD (HL),A
DEC HL
LD (HL),B
HALT
END