Re: A86: data
[Prev][Next][Index][Thread]
Re: A86: data
There's an instruction to do that, and it is quicker/smaller than what you
have:
ld a,4 ; compare with 4
ld b,a ; set BC to 1028, which should be longer than all your data
ld c,a ; if you have a set amount of data and want to stop,
stuff_end-stuff would work
ld hl,stuff ; point to the data
cpir ; stop when (hl) is equal to A, or when BC = 0
stuff:
.db 0,1,3,2,1,5,4,6,13,4
stuff_end:
> >I'm new to assembly programming, and I'd like to know something:
> >
> >how would you read one byte at a time from something like this:
> >
> >stuff:
> > .db 0,1,3,2,1,5,4
> >
> >then compare it with a number (lets say 4), and if its 4, you end?
> ld hl,stuff ;Load the memory adress of first byte into hl
> ld c,4 ;Load c with the value you want to break the loop
> Loop: ;Place to come back to if not the right value (Label)
> ld a,(hl) ;Load a with the byte stored at the adress hl
> inc hl ;increment the aderss to the next byte
> cp c ;compare the value in c with a, if the same set zero flag
> jr nz,Loop ;Go to the label Loop if the zero flag is not set
References: