flat assembler
Message board for the users of flat assembler.
Index
> DOS > (newbe) Problem printing array value |
Author |
|
gunblade 15 Aug 2005, 20:09
arrays dont work that way in asm.. thats C your thinking of.
what you do is.. say you have an array of single bytes Code: array db 21, 40, 31 if you want the address of the first element, do Code: mov dx, array for the address of the second element, you take the base address (array) and add the number of elements you want to skip.. so: Code: mov dx, array+1 If this array was an array of words though (2bytes each, then to access the address of element 2, you would do: Code: mov dx, array+2 I hope that was kinda clear. Feel free to ask otherwise. |
|||
15 Aug 2005, 20:09 |
|
umen 16 Aug 2005, 13:19
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... 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,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 |
|||
16 Aug 2005, 13:19 |
|
Matrix 16 Aug 2005, 13:59
hi umen,
you have to make your own functions to use your arrays, my example Code: org $100 push ds ; in case of exe file push cs pop ds mov si,THEARRAY mov bx,0 call printelement mov si,THEARRAY mov bx,1 call printelement mov si,THEARRAY mov bx,2 call printelement mov si,THEARRAY mov bx,3 call printelement mov si,THEARRAY mov bx,4 call printelement mov si,THEARRAY mov bx,5 call printelement ;waitkey; xor ah,ah int 16h pop ds MOV AX,4C00H INT 21H THEARRAY: db "Array element1*","$","Array Element2*","$","Array Element3*","$","Bonus element*","$",0 ;THEARRAY: db "Array element1$","Array Element2$","Array Element3$","Bonus element$",0 ;THEARRAY: db "helloszia$","sziaszia$","imallright$",0 printelement: ; proc print array element, in a null terminated array ; (ds:)si = parameter input, bx=element to print, 0 is first or bx,bx jz .write .loop: lodsb or al,al ; out of range? jz .error cmp al,"$" jne .loop dec bx jmp printelement .error: ; display error message mov dx,.ermsg mov ah,9 int 21h jmp .done .write: lodsb or al,al jz .error dec si mov dx,si mov ah,9 int 21h .done: ret .ermsg: db "out of range.*","$" |
|||
16 Aug 2005, 13:59 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.