Search code examples
arraysassemblyx86dosa86

Populating an Array with 1-100 with A86 Assembly


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.


Solution

  • 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.