1

I am trying to write an assembly program that uses a procedure to populate an array with values 1-100. The code that I have so far is as follows:

jmp main

first100 dw 100 dup (?)

main:
call prepare
call populate
mov ax, first100[0]
call putDec

mov ah, 04c
int 021
include ioProcs.inc

prepare:
mov ax, 1
mov bx, 0
mov cx, 100
ret

populate:
mov first100[bx], ax
inc ax
inc bx
loop populate
ret

However, the first value in the array first100 turns into 513 as opposed to 1. It is probably something simple, but where am I messing up? Thank you much for your time.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 2
    You need to increment `bx` by 2, because addressing uses byte offsets and your items are 2 bytes each. – Jester Oct 28 '14 at 14:51
  • @Deleteme Please do not edit your questions in this manner. See http://meta.stackexchange.com/questions/5999/how-can-i-delete-my-account for proper procedure. – Jason C Nov 24 '14 at 01:16
  • @JasonC have been trying, no one is processing the request –  Nov 24 '14 at 01:18

1 Answers1

0

As @Jester mentioned you need to increment bx by two bytes in the populate loop.

You are creating an array of type dw, that is a word. It has a size of two bytes.

2501
  • 25,460
  • 4
  • 47
  • 87