assemblyx86data-segment

Using data segment


I'm currently writing a program that writes 20 first fibonacci numbers. What I'm currently asking is if this thing can be possibly done:

MOV DS, 3000H
MOV SI, 4000H
MOV DL, 123
MOV CL, 5
MOV DS:[SI+CL], DL

(This is just a general code that has nothing to do with fibonacci numbers) So it would write '123' into the memory in the address 3000H:4005H. Is that even possible? So I don't need to increase both SI and CL (I use CL to end the program when it reaches 20 or 14h in that matter).

EDIT: This is my actual code, but it's not writing the data properly.

cseg segment
assume cs:cseg
    Start:  mov ax, 3000h
            mov ds, ax
            mov si, 4000h
            mov bx, 0
            mov al, 1
            mov bl, 1
            mov ds:[si], al
            inc bx
            mov ds:[si+bx], bl
            inc bx
    Again:  mov dl, al
            add dl, bl
            mov al, bl
            mov bl, dl
            mov ds:[si+bx], dl
            inc bx
            cmp bx, 20
            jc Again
            int 3h
cseg    ends
end     Start

Solution

  • You should re-read the documentation explaining the 16 bit address modes.

    In short, you can only use a base register BX or BP, an index register SI or DI, and a constant displacement in effective addresses. As such, you could do:

    MOV AX, 3000H
    MOV DS, AX
    MOV SI, 4000H
    MOV DL, 123
    MOV BX, 5
    MOV [SI+BX], DL
    

    If your displacement is constant 4000H, then you can also write:

    MOV AX, 3000H
    MOV DS, AX
    MOV DL, 123
    MOV BX, 5
    MOV [4000H+BX], DL