0

I have the following assembly code. I've declared two arrays in my DS. Later in the code I move into BX the index number of the array element I want to access. The PRINT_CHAR process just sends the data in AL over a serial port to display on the screen. But for some reason, I can't seem to access the array elements. It just gives me some bogus value. The print_char process is definitely fine. I've tried both methods I know to access the array. Any help would be appreciated. Thanks!

    DATA_SEG    SEGMENT
ARRAY       DB  '1','2','3','1','2','3','4','5','6','4','5','6'
bottom2     DB  '7','8','9','7','8','9','*','0','#','*','0','#'
    DATA_SEG    ENDS



    topnumbers:
    cmp BX, 12
    jge bottom_numbers
    MOV AL,DS:ARRAY[BX] ; Stores character in AL (?)
    jmp NUMBERS

    bottom_numbers:
    sub BL, 12d
            LEA SI, bottom2
            ADD SI, BX
            MOV AL, [SI]

    NUMBERS:
    XOR AH, AH
    CALL FAR PTR PRINT_CHAR
2
  • What have you set DS to? Commented Oct 21, 2013 at 7:33
  • cannot believe i didnt realise that. thank you! Commented Oct 21, 2013 at 8:08

1 Answer 1

1

If you are creating .exe file, you are responsible to set the segment registers to the corresponding values. Something like (but check your secret assembler syntax as well):

    mov  ax, DATA_SEG
    mov  ds, ax

Besides, the above, for such small programs .COM executable format is much easier to handle, because DOS will set all segment registers for you and you will never need to use far pointers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.