You can't expect registers to retain their values between assembly snippets. You have three assembly snippets, with chunks of C between them, and they rely on bx
staying the same. The compiler makes no such promise.
Either use memory to store the running minimum, or reformulate with a single assembly snippet. For the latter approach, you'd have to rewrite the for loop and the array access in assembly; it's quite doable. Like this:
_asm{
mov dx, y ; we'll use dx instead of bx for the running minimum - long story
mov bx, a ; that's the array pointer
mov si, 0 ; that's our i
loop:
mov ax, [bx+si*2] ; read a[i] into ax; *2 because int is two bytes
cmp ax,dx
jge nxt
mov dx, ax
nxt:
;Now the for loop stuff
inc si ; i++
cmp si, 5 ; compare i to 5
jl loop ; if less, continue looping
; End of loop
mov res,dx;
}
I'm using bx and si for base+index memory access because on early x86 CPUs, you could only do that kind of memory access with a limited subset of registers (bx or bp for base, si or di for index). These days, you can use any combination of registers; but I'm not sure if antique Turbo C would take that.