A83: Sv: What CPIR does! was (No Subject)- corrected
[Prev][Next][Index][Thread]
A83: Sv: What CPIR does! was (No Subject)- corrected
Thanks.. I was really wondering :)
Looking forward to have more time to fool around with this...
***
Thomas Turn Jensen
Icq uin => 8128636
IRC, Undernet => Mukke
***
Får computeren dig til at sukke?
Så kald da blot på Mukke
***
-----Oprindelig meddelelse-----
Fra: Ben Wise <bwise@labyrinth.net.au>
Til: assembly-83@lists.ticalc.org <assembly-83@lists.ticalc.org>
Dato: 18. november 1998 02:27
Emne: A83: What CPIR does! was (No Subject)- corrected
>
>Well guys I just thought it should be my turn to explain some source code, I
>hope this helps and that it is correct!!
>
>CPIR
>Ok well as you will remember Pat Milherton's code went like this:
>ld a,(something)
>ld hl,numbers
>ld bc,3
>cpir
>jp z,aroutine
>
>numbers: db 1,3,65
>
>Which simply performs an
>If a==1 or a==3 or a==65
>Then
>etc..
>End
>Ok so the (something) is what we are comparing to see if it is 1, 3 or 65..
>read Olle's message about parenthesis for info on "(something)"... CPIR
>stands for (IMHO) ComPare, Increment and Repeat....
>Bascially this instruction compares whatever hl points to (again see Olle's
>post on "(something) - parenthesis" with what is in register a...
>This continues until either:
> bc==0
> a==(hl)
>where in this case (hl) can be either 1, 3 or 65
>Every time the instrution "repeats":
> bc is deincremented (e.g. bc=bc-1)
> hl is _incremented_ (e.g. hl=hl+1) - Hence compare Increment and repeat.
>So to step through that code for the first couple of increments ...
>
>ld a,(something)
>;a will now contain the number 3
>ld hl,numbers
>;hl contains the _address_ of the label numbers
>ld bc,3
>;bc contains the number three, because there are three numbers we want to
>compare a to...
>cpir
>;now the cpir instuction has been fed the correct stuff:
> ;a=3
> ;hl = start of numbers
> ;bc = number of things to compare (3)
>;the CPIR instruction will continue as I said before until a==(hl) or bc=0,
>if a match is found, then CPIR will stop, and set the Zero flag, so:
>jp z,aroutine
>;A match is found in this case since a=3, therefore the code will now branch
>to the code at aroutine
>;code for no match continues here.....
>
>. . .
>. . .
>aroutine:
>the routine etc....
>
>
>numbers: db 1,3,65
>something: db 3
>
>Ok that's one big post, hope that helps and if you 've got any questions
>email me!
>
>