flat assembler
Message board for the users of flat assembler.
Index
> DOS > String arrays |
Author |
|
LocoDelAssembly 14 Jul 2007, 15:52
(adaptation of the example of fasm doc)
Code: macro strtbl name,[string] { common label name word forward local label dw label forward label dw string,0 } strtab meses, 'January',\ 'February',\ 'March',\ 'April',\ 'May',\ 'June',\ 'July',\ 'August',\ 'September',\ 'October',\ 'November',\ 'December' Then, to get a pointer to a month you do this Code: getMonthPointer: ; AX = month number (starting from zero) push bx add ax, ax mov bx, ax mov ax, [bx+meses] pop bx ret; AX = pointer to month It is still possible to make all string with the same length but I think this way is better. Ask if you want the fixed length string version too |
|||
14 Jul 2007, 15:52 |
|
flash 16 Jul 2007, 02:53
ThankĀ“s, but your function does not work to me. As far as I understand, the getMonthPointer function must return the value of the lement addresses. But why the duplicated value of index? Are you assuming fixed size of 2bytes for each element. If I am not wrong, the code
Code: macro strtab name,[string] { common label name word forward local label dw label forward label dw string,0 } Shoul store the address of each element befor it self and the "attached zero" Because of this I do not understand getMonthPointer |
|||
16 Jul 2007, 02:53 |
|
LocoDelAssembly 16 Jul 2007, 03:05
Example
Code: org $100 ; Should print July mov ax, 7-1 call getMonthPointer mov dx, ax mov ah, 9 int $21 xor ax, ax int $16 int $20 getMonthPointer: ; AX = month number (starting from zero) push bx add ax, ax mov bx, ax mov ax, [bx+meses] pop bx ret ; AX = pointer to month macro strtbl name,[string] { common label name word forward local label dw label forward label db string,'$' } strtbl meses, 'January',\ 'February',\ 'March',\ 'April',\ 'May',\ 'June',\ 'July',\ 'August',\ 'September',\ 'October',\ 'November',\ 'December' I modified the macros to finish with '$' instead of zero but I did it just to make the strings suitable for INT21/AH=09. Try again, my previous post had some typo errors ("label dw string,0" instead of "label db string,0" and "strtab meses" instead of "strtbl meses"). |
|||
16 Jul 2007, 03:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.