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
2
  • Why are you using hardcoded addresses? Commented Jan 13, 2015 at 12:57
  • I just started studying Assembly and that's how my teacher taught me. Commented Jan 13, 2015 at 13:16

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

7 Comments

But how will it write it to 3000H:4005H if not using DS:?
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.
Can you tell me what's the problem with my code? I edited my original post.
bl is the low byte of bx, looks like you have conflicting uses.
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.
|

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.