Bogdan M.
Bogdan M.

Reputation: 2181

Assembly 80286: Accessing n-th byte of variable

(asm 80286) Data segment variable accessing, on a array of type byte or word?

I am trying to access the n-th byte/ word of a variable but something is wrong and i dont know wha

ASSUME cs: code, ds:data 
data SEGMENT
    s db 5,1,2,3

data ENDS 
code SEGMENT 
start: 
mov ax,data 
mov es,ax 
mov si, 0;
    mov ax, 0;
    check:  
        cmp si, len   
        jg fin
        mov al, byte ptr [s][si] ; !!! this return not the value i i think it would
                 ^^^^^^^^^^^^^^^
        cmp al, 0
        jl  negativ   ; move to positiv 
        jmp positiv   ; move to negativ 

    positiv:
        mov byte ptr d1[si],al
        inc si
        jmp check
    negativ:  
        mov byte ptr d2[si],al
        inc si
        jmp check   
    fin:
mov ax,4C00h          
int 21h 
code ENDS 
END start

The get to debug : tasm name , tlink name, td name The ^^^^^^^^ line is returning me wrong values, thats why i assume i checked with the debugger and the values are from data segment, but not the correct ones.

I think I might not have understand the addressing methods corectly, could anyone help me? Thank you.

Upvotes: 1

Views: 87

Answers (1)

rkhb
rkhb

Reputation: 14409

You forgot to initialise DS.

Change

mov ax,data 
mov es,ax

to

mov ax,data
mov ds,ax
mov es,ax

Is the initialisation of ES really needed?

Upvotes: 1

Related Questions