.text
mov.w #List,R5; move the first address of List to R5
mov.w #List+10,R6; same as R5+10 to R6
mov.w #Index,R12; move the address of Index to R12
mov.b Goal,R8;
call #binary; call binary subroutine
sub.w #0x2400,R7; R7-2400 give to R7 .The position of the value
mov.b R7,0(R12); store the final value
jmp $;
binary:
cmp.b #10,counter; compare with the mid number
jge action; jump to action if greater or equal
mov.w R6,R7;
add.w R5,R7; the add of the first and end address
rra.w R7; R7/2 get the mid address
mov.b R7,R10;
cmp.b R8,R10; compare to know if we get the Goal
jge Left; jump to Left if greater or equal
jl Right; jump to Right if less
Left:
cmp.b R8,R10; judge if R8=R10
jeq Done;
mov.w R7,R6; give the high Index to R6
add.b #1,counter; counter+1;
jmp binary;
Right:
mov.w R7,R5; give the low Index to R5
add.b #1,counter; counter+1
jmp binary;