(newbe) Problem printing array value

Started by umen, August 14, 2005, 08:36:34 AM

Previous topic - Next topic

umen

Hello all
im trying to print the array value put with out success, it always prints me the first array member value
here is the code :

THEARRAY DB '1000$','2000$','3000$','4000$','5000$'                                         
DSEG ENDS
SSEG SEGMENT STACK                             
DW  100H DUP(0)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG,CS:CSEG
START:
MOV DX,OFFSET THEARRAY[0]
    MOV AH,9
    INT 21H
MOV DX,OFFSET THEARRAY[1]
    MOV AH,9
    INT 21H
MOV DX,OFFSET THEARRAY[3]
    MOV AH,9
        INT 21H
    MOV AX,4C00H
    INT 21H
CSEG ENDS
END START

what im doing wrong here?
thanks

joe

I think, that error is in offset:
MOV DX,OFFSET THEARRAY[0]   ;adresses THEARRAY, it mean 1. character (THEARRAY+0)='1'
MOV DX,OFFSET THEARRAY[1]   ;adresses THEARRAY, it mean 2. character (THEARRAY+1) ='0'
MOV DX,OFFSET THEARRAY[3]   ;adresses THEARRAY, it mean 4. character (THEARRAY+3) ='0'
It don't recognize arrays of strings (by me), but arrays of bytes.
Try use:
MOV DX,OFFSET THEARRAY[0]  ;to print string '1000'
MOV DX,OFFSET THEARRAY[5]  ;to print string '2000'
MOV DX,OFFSET THEARRAY[9]  ;to print string '4000'

joe

EDIT:
To print '4000'
  MOV DX,OFFSET THEARRAY[14]

hutch--

umen,

I moved the question to the 16 bit forum so you would get more answers. The other forums are for 32 bit assembler.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

umen

Hello and tnx for the fast reply
i did the changed you suggested but im still getting only printed 1000
what im missing here?
here is the code:
-----------------------------------------------------------
DSEG SEGMENT
THEARRAY DB '1000$','2000$','3000$','4000$','5000$'                                         
DSEG ENDS
SSEG SEGMENT STACK                             
DW  100H DUP(0)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG,CS:CSEG
START:
MOV DI,0
MOV DX,OFFSET THEARRAY[0]
   MOV AH,9
   INT 21H
   INC DI
MOV DX,OFFSET THEARRAY[4]
   MOV AH,9
   INT 21H
   INC DI
MOV DX,OFFSET THEARRAY[9]
   MOV AH,9
        INT 21H
MOV DX,OFFSET THEARRAY[14]
   MOV AH,9
        INT 21H
    MOV AX,4C00H
    INT 21H
CSEG ENDS
END START

joe

I can't test 16-bit apps. I missed.
'1000$','2000$','3000$','4000$','5000$'
01234  56789   11111  11111   22222                     offset
                        01234  56789   01234
MOV DX,OFFSET THEARRAY[0]
MOV DX,OFFSET THEARRAY[5]
MOV DX,OFFSET THEARRAY[10]
MOV DX,OFFSET THEARRAY[15]
MOV DX,OFFSET THEARRAY[20]
In my previous answer it was wrong adressed to '$'
Excuse me, please, this, mistake.

umen

well i guess ... im not sure that the problem is in printing the actual value of the element array.
i dont know .. when i run the compiled exe it prints me 1000 five times
can some one run this short code and tell me if it works for him?
thanks

joe

I look to Your code. I'm not sure if it's possible to use THEARRAY[5]. Are there still problem with THEARRAY+5?

umen

What you mean THEARRAY+5 ?
sorry i didnt understand u.

umen

Ok first tnx for the reply .. this is confusing me a lot this simple array manipulation just don't work in any way I try to print the element
Please.. please some one take this code and try to run it .. it is just don't work. let me understand why...
------------------------------------------------------------------------
DSEG SEGMENT
THEARRAY DB 23,56,88,99
DSEG ENDS
SSEG SEGMENT STACK
DW 100H DUP(0)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG,CS:CSEG
START:
MOV DX,THEARRAY
MOV AH,9
INT 21H
MOV DX,THEARRAY+1
MOV AH,9
INT 21H
MOV DX,THEARRAY+2
MOV AH,9
INT 21H
MOV DX,THEARRAY+3
MOV AH,9
INT 21H
MOV AX,4C00H
INT 21H
CSEG ENDS
END START
------------------------------------------------------------------------
this one gives me this error:
tst1.asm(10) : error A2070: invalid instruction operands
tst1.asm(13) : error A2070: invalid instruction operands
tst1.asm(16) : error A2070: invalid instruction operands
tst1.asm(19) : error A2070: invalid instruction operands
-----------------------------------------------------------------------
when i try this code :

DSEG SEGMENT
THEARRAY DB 23,56,88,99
DSEG ENDS
SSEG SEGMENT STACK
DW 100H DUP(0)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG,CS:CSEG
START:
MOV DX,OFFSET THEARRAY
MOV AH,9
INT 21H
MOV DX,OFFSET THEARRAY+1
MOV AH,9
INT 21H
MOV DX,OFFSET THEARRAY+2
MOV AH,9
INT 21H
MOV DX,OFFSET THEARRAY+3
MOV AH,9
INT 21H
MOV AX,4C00H
INT 21H
CSEG ENDS
END START
-----------------------------------------------------------------------
the result is bench of crap on the screen ....


what is wrong here ? please help
thenks allot

hutch--

umen,

You are getting the problem because you are trying to handle a byte array like a high level string array.

See if 16 bit masm will handle the string data someting like this.

.data
  string1 db "string1$"
  string2 db "string2$"
  string3 db "string3$"
  string4 db "string4$"

  array dw string1,string2,string3,string4


Access the array of word addresses then dereference the result to get the string data.

I am sory I cannot set up a test for you but I don't keep 16 bit DOS code working.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

joe

I'm sorry for my previous answers. It was not tested. Usually I don't use 16-bit assember.
Which compiler do You use? Probably is problem in segmentation of memory.
I tested this code in Tasm 2.0, it seems to be OK:
DSEG SEGMENT
THEARRAY DB '1000$','2000$','3000$','4000$','5000$'                                         
DSEG ENDS
SSEG SEGMENT STACK                             
DW  100H DUP(0)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG,CS:CSEG
START:
MOV DI,0
MOV DX,OFFSET THEARRAY   ;1000
  add dx,256
   MOV AH,9
   INT 21H
   INC DI
MOV DX,OFFSET THEARRAY   ;2000
   add dx,256+5
   MOV AH,9
   INT 21H
   INC DI
MOV DX,OFFSET THEARRAY   ;3000
   add dx,256+10
   MOV AH,9
   INT 21H
   INC DI
MOV DX,OFFSET THEARRAY   ;4000
   add dx,256+15
   MOV AH,9
   INT 21H
   INC DI
MOV DX,OFFSET THEARRAY   ;5000
   add dx,256+20
   MOV AH,9
   INT 21H
    MOV AX,4C00H
    INT 21H
CSEG ENDS
END START

tenkey

Yup, it's a segmentation problem.

When you build a DOS EXE, you need to set up the DS and ES registers to point to the correct segment. They are set up to point to the PSP segment. The PSP contains a few interesting things, for example, the "command line tail" at data offset 81H.

You would normally code something like

mov ax,seg dseg
mov ds,ax
mov es,ax

at the beginning (after the START label). (After which, you won't need to add the extra 256 to get the correct address.)
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

umen

joe ! tnx allot this working just fine
can you please tell just why you start the count after you insert 256 to DX?
again thanks allot

umen

tnx again folks , i improved my code to print the array with loop
and then change the bit of every element of the array , but i encored with another problem
when i changing the bit's in the elements array the output is kinda wired . see in the example what i mean :
---------------------------------------------------------------------------------------------------------------------------------------------------------------
DSEG SEGMENT
THEARRAY DB '1000$','2000$','3000$','4000$','5000$' 
LINEBREAK DB 0DH,0AH,'$'
INTMSG DB 'This is the array:',0DH,0AH,0DH,0AH,'$'
AFTERMSG DB 'This is the array after switching the bits:',0DH,0AH,0DH,0AH,'$'
DSEG ENDS
SSEG SEGMENT STACK                             
DW  100H DUP(0)
SSEG ENDS
CSEG SEGMENT
ASSUME DS:DSEG,SS:SSEG,CS:CSEG
START:
MOV AH,9
MOV DI,5
MOV CX,0
MOV DX,OFFSET INTMSG 
   ADD DX,256
   INT 21H
AGAIN : MOV DX,OFFSET THEARRAY
   ADD DX,256
   ADD DX,CX
   ADD CX,5
   INT 21H
      MOV DX,OFFSET LINEBREAK
      ADD DX,256
      INT 21H
        DEC DI
   JNZ AGAIN
;switching the bits of the array
MOV DX,OFFSET AFTERMSG 
ADD DX,256
INT 21H


MOV DI,5
MOV CX,0

AGAIN2 : MOV DX,OFFSET THEARRAY
   ADD DX,256
   ADD DX,CX
   ADD CX,5
   MOV SI,4
   MOV AL ,'X'
   MOV BX,OFFSET DX
   CHANGE:MOV [BX+SI],AL
          DEC SI
   JNZ CHANGE
   MOV [BX+SI],AL
   INT 21H
      MOV DX,OFFSET LINEBREAK
      ADD DX,256
      INT 21H
                DEC DI
JNZ AGAIN2

   

    MOV AX,4C00H
    INT 21H
CSEG ENDS
END START
--------------------------------------------------------------------------------------------
The output is :
This is the array:

1000
2000
3000
4000
5000
This is the array after switching the bits:

XXXXX2000
XXXXX3000
XXXXX4000
XXXXX5000
XXXXX

as you can see in the second part it prints me the actual initial element value ( 2000,3000.4000......)
and from what i understand ( and need ) i like it to print only the XXXXXX instead of every element array
so what is wrong here?

thanks
allot