0

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
HelloWorld
  • 1,128
  • 1
  • 7
  • 14

1 Answers1

1

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
Jester
  • 56,577
  • 4
  • 81
  • 125
  • But how will it write it to 3000H:4005H if not using DS:? – HelloWorld Jan 13 '15 at 13:08
  • It is using `DS` by default, you do not need to specify that. You only need an override if what you want doesn't match the default. Obviously I assumed `DS` has been set to `3000H`, I omitted that part from the code. Note that `MOV DS, 3000H` is illegal, you have to go through a register. – Jester Jan 13 '15 at 13:09
  • Can you tell me what's the problem with my code? I edited my original post. – HelloWorld Jan 13 '15 at 13:15
  • `bl` is the low byte of `bx`, looks like you have conflicting uses. – Jester Jan 13 '15 at 13:26
  • No, this is not about that. It worked when I incread CL and SI both without using [SI+BX]. I just replaced my CL to BX and stopped increasing SI, but it doesn't write the data properly and in incorrect addresses. – HelloWorld Jan 13 '15 at 13:34
  • Oh I didn't get what you're saying in the beginning, but noticed it. Replaced BX by BP and it works great now. Thanks a lot! @Jester – HelloWorld Jan 13 '15 at 13:43
  • Trust me, it is **exactly** that, and I have the [screenshot to prove it](http://i.stack.imgur.com/SOLxE.png). EDIT: oh okay, cool :) PS: the numbers starting with the 14th no longer fit into a single byte. – Jester Jan 13 '15 at 13:45