N equ 30 ; array count notfound equ -1 key equ 190 ; define the searching key org $1000 result rmw 1 ; reserve a word for result org $1500 ; starting address of the program ldy #N ; set up loop count ldd #notfound std result ; initialize the search result ldd #key ldx #vec_x ; place the starting address of vec_x in X loop cpd 2,X+ ; compare the key with array element beq found dbne Y,loop ; decrement the count and check if done bra done found dex dex stx result done swi vec_x dw 13,15,320,980,42,86,130,319,430,4 dw 90,20,18,55,30,51,37,89,550,39 dw 78,1023,897,930,880,810,650,710,300,190 end