I have a subroutine that is passed a pointer to a bit string in the si reg and an index in the ax register. I declared the val variable in the data seg

getbit: 
cmp ax, 1783 ; max value of the index being passed
ja goback
push si
mov [val], ax
add si,val
mov ax,[si]
pop si
goback:ret

Is what I have, but it's not giving me the expected value, any help would be appreciated.

If you're using the variable val just to do this:

mov [val], ax
add si,val

then there's no need to do so,just do it directly

add si,ax

It's quite difficult to understand what you're trying to do, the information provided here is too little(not enough) and as far as your sample code is concerned, syntactically it's fine.
Here's an example, I hope this will help .
suppose there's a string defined as

string    db "ABCDEFGH",'$'

and it's characters can be accessed like this

mov bx,offset string
mov al,[bx+si];al = "A"
add si,02
mov al,[bx+si];al="C"

or like this

mov al,[string+si];al="A"
add si,02
mov al,[string+si];al="C"

Sorry if I didn't make myself clear, the goal of this subroutine is to find the nth bit of a bit string. the n is being based in the ax reg and the pointer to the bit string is being pulled from the si reg. The value of the nth bit in the bit string will be returned along the ax variable.

This is the code I have so far, but does not appear to be giving me the values I need

push si       ;save SI
      add si, ax    ;move SI to correct location by adding ax
      mov ax, [si]  ; move the value of si into ax
      test ax, 01h  ; test the lowest bit of ax
      je zerobit    ; if zero, goto zerobit
      mov ax,01h    ;else move then move 1 into ax
      jmp done      ; finish
    zerobit: 
       mov ax,00h ; move 0 into ax
         
      done:pop si
 
 
goback:ret ;return
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.