Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem in printing array value

pokka2011pokka2011 Member Posts: 1
Hi,

I have encounter problem while i need to display a series number from a array. I am new to X86 assembly language. Can someone guide me or please correct me my mistake.
I am using emu8086 to write the program.

Task : array1 1,2,3,4,5,6,7,8,910
I have 10 elements in this array and i would like to display all of them. I try to write out the code as shown at below, unfortunately, the screen cannot show me the result 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,.

Please correct me and give me advice.

Thank you.

data segment
; add your data here!
pkey1 db ', $'
pkey2 db "are the positive integer elements that pre-stored in my array.$"


data ends

stack segment
dw 1024 dup(0)
stack ends

code segment
ASSUME ss:stack, ds:data, cs:code
start:
; set segment registers:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax



; add your code here
jmp c_array1
array1 db 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
;Calculate the number of elements in array
c_array1:
array1_byte_size = $ - offset array1
mov cx, array1_byte_size

lea si, array1
number:
mov di, offset array1[si]
mov dx, di
mov ah, 9
int 21h ; output string at ds:dx

mov dx, offset pkey1
mov ah, 9
int 21h ; output string at ds:dx

inc si
dec cx
jnz number

mov dx, offset pkey2
mov ah, 9
int 21h ; output string at ds:dx

; wait for any key....

mov ah, 1
int 21h

mov ax, 4c00h ; exit to operating system.
int 21h
code ends

end start ; set entry point and stop the assembler.
Sign In or Register to comment.