0

I have this code on Emu8086:

Mov Bx,0000h
Mov Cx,0ah 
Mov Si,0200h
Fillup:
Mov Ax,Array[bx]
Mov Ds:[Si],Ax
Inc Bx
inc si                           
loop FillUp

Array dw 28h,43h,0a4h,4ch,81h,21h,0ceh,0fh,2dh,87h

When emulating this happens:

Image

The memory table looks like this:

Address Value
0200 28
02001 00
02002 43
02003 00
02004 a4

Enter the digit every two steps, and I don't know why it happens.

I have tried many ways to cycle, but I can't find the solution.

One last qustion

How can I initialize an array of n elements at a specific memory address?

For example, how can I make my entire array of 10 elements that are from the address 0200h? Without moving from the array to the memory address.

3
  • 1
    What is it supposed to do? Note that your Array is an array of words (because of dw) and so Array itself contains the bytes 28h, 00h, 43h, 00h, a4h, 00h, etc. Is that what you wanted? Keep in mind x86 is little-endian and so dw 28h is the two bytes 28h,00h in that order. Commented Jan 17, 2021 at 0:33
  • It's true, obviously, more simpler impossible Many many many thanks :D Commented Jan 17, 2021 at 0:45
  • One last question how to initialize an array of n elements at a specific memory address For example, how can I make my entire array of 10 elements that are from the address 0200h. Without moving from the array to the memory address. I hope I could have explained myself, thanks Commented Jan 17, 2021 at 2:10

2 Answers 2

1

Like most modern processors, it is byte addressable.  This means that each byte gets its own address, and when we group bytes to make larger word sizes, then that word in memory occupies multiple byte addresses.

We need to consistently tell the processor the same data sizes for the same data types.  The processor doesn't know about data declarations and remember their types the way high level languages do: it sees only instructions, and every instruction that manipulates data — in some sense — must tell the processor how many bytes the data occupies.

Here's a list of things that need to be consistent:

  • Pointer size increments — add 2 to pointer to access next word-sized data
  • Index scaling — scale an index by 2 for word-sized data
  • Data declaration — use dw for word-sized data
  • Load & store size — use word-sized loads & stores
    • by using word sized source or target register (e.g. ax, bx, vs. al, bl)
    • by using "word ptr" or "word" as per your assembly language
Sign up to request clarification or add additional context in comments.

Comments

0

The source is an array of words. Change 'dw' to 'db'.

5 Comments

Hours of watching the code screen blinded me, I need a break .
@Ckris: Just changing dw to db would mean you're still doing word loads, and still only incrementing your pointer by 1, so the words will overlap. That might or might not be ok if you correctly handle the end of the array to avoid an over-read / over-write past the end of where you meant to copy to.
One last question how to initialize an array of n elements at a specific memory address For example, how can I make my entire array of 10 elements that are from the address 0200h. Without moving from the array to the memory address. I hope I could have explained myself, thanks
Depending on what you are trying to achieve, how you used or what assembler you are using, instruction ORG 200h or ABSOULTE 200h may help work for you, or not.
And as others suggested, if you are moving on byte at a time, you should change mov ax, array[bx] to mov al,byte ptr array[bx] and mov ds:[si],ax to mov byte ptr ds:[si],al. You could also familiarize yourself with rep movsb instruction.

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.