flat assembler
Message board for the users of flat assembler.
Index
> Main > [SOLVED] converting MASM to FASM (3d array). |
Author |
|
revolution 10 Feb 2012, 14:00
Hints:
Replace "dseg segment para public 'data'" with "segment dseg" Remove "dseg ends" Replace "byte" with "db" Replace "word" with "dw" Replace "dword" with "dd" |
|||
10 Feb 2012, 14:00 |
|
FASMNOOB 10 Feb 2012, 15:21
What about cseg, the part "assume cs:cseg, ds:dseg"? anyways now I get an error around the part with the dseg. Do I always need to use org 100h?
Code: org 100h; code starts at offset 100h use16; use 16-bit code segment dseg ; Indices we will use for the arrays. J dw 1 K dw 2 L dw 3 ; Some two-dimensional arrays. ; Note how this code uses the "dup" operator to suggest the size ; of each dimension. B2Ary db 3 dup (4 dup (?)) W2Ary dw 4 dup (3 dup (?)) D2Ary dd 2 dup (6 dup (?)) ; 2D arrays with initialization. ; Note the use of data layout to suggest the sizes of each array. B2Ary2 db 0, 1, 2, 3 db 4, 5, 6, 7 db 8, 9, 10, 11 W2Ary2 dw 0, 1, 2 dw 3, 4, 5 dw 6, 7, 8 dw 9, 10, 11 D2Ary2 dd 0, 1, 2, 3, 4, 5 dd 6, 7, 8, 9, 10, 11 ; A sample three dimensional array. W3Ary dw 2 dup (3 dup (4 dup (?))) ;dseg ends cseg segment para public 'code' assume cs:cseg, ds:dseg Main proc mov ax, dseg ;These statements are provided by mov ds, ax ; shell.asm to initialize the mov es, ax ; segment register. ; AL := B2Ary2[j,k] mov bx, J ;index := (j*4+k) add bx, bx ;j*2 add bx, bx ;j*4 add bx, K ;j*4+k mov al, B2Ary2[bx] ; AX := W2Ary2[j,k] mov ax, J ;index := (j*3 + k)*2 mov bx, 3 mul bx ;(j*3)-- This destroys DX! add ax, k ;(j*3+k) add ax, ax ;(j*3+k)*2 mov bx, ax mov ax, W2Ary2[bx] ; EAX := D2Ary[i,j] mov ax, J ;index := (j*6 + k)*4 mov bx, 6 mul bx ;DX:AX := j*6, ignore overflow in DX. add ax, k ;j*6 + k add ax, ax ;(j*6 + k)*2 add ax, ax ;(j*6 + k)*4 mov bx, ax mov eax, D2Ary[bx] ; Sample access of a three dimensional array. ; ; AX := W3Ary[J,K,L] mov ax, J ;index := ((j*3 + k)*4 + l)*2 mov bx, 3 mul bx ;j*3 add ax, K ;j*3 + k add ax, ax ;(j*3 + k)*2 add ax, ax ;(j*3 + k)*4 add ax, l ;(j*3 + k)*4 + l add ax, ax ;((j*3 + k)*4 + l)*2 mov bx, ax mov ax, W3Ary[bx] Quit: mov ah, 4ch ;Magic number for DOS int 21h ; to tell this program to quit. Main endp cseg ends sseg segment para stack 'stack' stk db 1024 dup ("stack ") sseg ends zzzzzzseg segment para public 'zzzzzz' Lastdbs db 16 dup (?) zzzzzzseg ends end Main |
|||
10 Feb 2012, 15:21 |
|
revolution 10 Feb 2012, 15:51
Well the dseg replacement above was an example intended to be applied to all the segment statements. Remove all the "ends" lines.
Just delete the "assume" thing. And also replace "proc" with a colon (:) and delete the endp line since you don't have any macros to define what "proc" means. If you use org 0x100 then you probably want to create a com file, but the code suggests you want an exe file. Try using format mz. See the example in the DOS fasm download for "multiseg". Last edited by revolution on 10 Feb 2012, 16:57; edited 1 time in total |
|||
10 Feb 2012, 15:51 |
|
FASMNOOB 10 Feb 2012, 16:19
Thanks so far, I made the following changes below. Now its the declaration in the data segment thats wrong, not sure why. I did follow this page to get an idea for the MZ format. Is that also 16 bit mode or is it also 32 bit as well?
This is the error B2Ary db 3 dup (4 dup (?)) Code: format MZ ;org 100h; code starts at offset 100h use16; use 16-bit code entry cseg:Main stack 100h segment dseg ; Indices we will use for the arrays. J dw 1 K dw 2 L dw 3 ; Some two-dimensional arrays. ; Note how this code uses the "dup" operator to suggest the size ; of each dimension. B2Ary db 3 dup (4 dup (?)) W2Ary dw 4 dup (3 dup (?)) D2Ary dd 2 dup (6 dup (?)) ; 2D arrays with initialization. ; Note the use of data layout to suggest the sizes of each array. B2Ary2 db 0, 1, 2, 3 db 4, 5, 6, 7 db 8, 9, 10, 11 W2Ary2 dw 0, 1, 2 dw 3, 4, 5 dw 6, 7, 8 dw 9, 10, 11 D2Ary2 dd 0, 1, 2, 3, 4, 5 dd 6, 7, 8, 9, 10, 11 ; A sample three dimensional array. W3Ary dw 2 dup (3 dup (4 dup (?))) ;dseg ends segment cseg Main: mov ax, dseg ;These statements are provided by mov ds, ax ; shell.asm to initialize the mov es, ax ; segment register. ; AL := B2Ary2[j,k] mov bx, J ;index := (j*4+k) add bx, bx ;j*2 add bx, bx ;j*4 add bx, K ;j*4+k mov al, B2Ary2[bx] ; AX := W2Ary2[j,k] mov ax, J ;index := (j*3 + k)*2 mov bx, 3 mul bx ;(j*3)-- This destroys DX! add ax, k ;(j*3+k) add ax, ax ;(j*3+k)*2 mov bx, ax mov ax, W2Ary2[bx] ; EAX := D2Ary[i,j] mov ax, J ;index := (j*6 + k)*4 mov bx, 6 mul bx ;DX:AX := j*6, ignore overflow in DX. add ax, k ;j*6 + k add ax, ax ;(j*6 + k)*2 add ax, ax ;(j*6 + k)*4 mov bx, ax mov eax, D2Ary[bx] ; Sample access of a three dimensional array. ; ; AX := W3Ary[J,K,L] mov ax, J ;index := ((j*3 + k)*4 + l)*2 mov bx, 3 mul bx ;j*3 add ax, K ;j*3 + k add ax, ax ;(j*3 + k)*2 add ax, ax ;(j*3 + k)*4 add ax, l ;(j*3 + k)*4 + l add ax, ax ;((j*3 + k)*4 + l)*2 mov bx, ax mov ax, W3Ary[bx] Quit: mov ah, 4ch ;Magic number for DOS int 21h ; to tell this program to quit. segment sseg stk db 1024 dup ("stack ") segment zzzzzzseg Lastdbs db 16 dup (?) |
|||
10 Feb 2012, 16:19 |
|
revolution 10 Feb 2012, 17:04
You are almost there.
fasm doesn't support nested dup operations, you will need to flatten them to one level: db (3*4) dup ? Also this: B2Ary2[bx] will need to be changed to this: [B2Ary2+bx] |
|||
10 Feb 2012, 17:04 |
|
FASMNOOB 10 Feb 2012, 17:14
Thanks, looks like the following compiles. I just have two more questions.
1. Why does he use this " mov es, ax ; segment register."? 2. How would I layout a 3d array. notice he only gave examples for the 2d case. Code: format MZ ;org 100h; code starts at offset 100h ;use16; use 16-bit code entry cseg:Main ;stack 100h ;dseg ends segment cseg Main: mov ax, dseg ;These statements are provided by mov ds, ax ; shell.asm to initialize the mov es, ax ; segment register. ; AL := B2Ary2[j,k] mov bx, J ;index := (j*4+k) add bx, bx ;j*2 add bx, bx ;j*4 add bx, K ;j*4+k mov al, [B2Ary2+bx] ; AX := W2Ary2[j,k] mov ax, J ;index := (j*3 + k)*2 mov bx, 3 mul bx ;(j*3)-- This destroys DX! add ax, K ;(j*3+k) add ax, ax ;(j*3+k)*2 mov bx, ax mov ax, [W2Ary2+bx] ; EAX := D2Ary[i,j] mov ax, J ;index := (j*6 + k)*4 mov bx, 6 mul bx ;DX:AX := j*6, ignore overflow in DX. add ax, K ;j*6 + k add ax, ax ;(j*6 + k)*2 add ax, ax ;(j*6 + k)*4 mov bx, ax mov eax, [D2Ary+bx] ; Sample access of a three dimensional array. ; ; AX := W3Ary[J,K,L] mov ax, J ;index := ((j*3 + k)*4 + l)*2 mov bx, 3 mul bx ;j*3 add ax, K ;j*3 + k add ax, ax ;(j*3 + k)*2 add ax, ax ;(j*3 + k)*4 add ax, L ;(j*3 + k)*4 + l add ax, ax ;((j*3 + k)*4 + l)*2 mov bx, ax mov ax, [W3Ary+bx] Quit: mov ah, 4ch ;Magic number for DOS int 21h ; to tell this program to quit. segment dseg ; Indices we will use for the arrays. J dw 1 K dw 2 L dw 3 ; Some two-dimensional arrays. ; Note how this code uses the "dup" operator to suggest the size ; of each dimension. B2Ary db (3*4) dup ? ;3 dup (4 dup (?)) W2Ary dw (4*3) dup ? ; 4 dup (3 dup (?)) D2Ary dd (2*6) dup ? ;2 dup (6 dup (?)) ; 2D arrays with initialization. ; Note the use of data layout to suggest the sizes of each array. B2Ary2 db 0, 1, 2, 3 db 4, 5, 6, 7 db 8, 9, 10, 11 W2Ary2 dw 0, 1, 2 dw 3, 4, 5 dw 6, 7, 8 dw 9, 10, 11 D2Ary2 dd 0, 1, 2, 3, 4, 5 dd 6, 7, 8, 9, 10, 11 ; A sample three dimensional array. W3Ary dw (2*3*4) dup ? ;2 dup (3 dup (4 dup (?))) ;segment sseg ;stk db 1024 dup ("stack ") ;segment zzzzzzseg ;Lastdbs db 16 dup (?) |
|||
10 Feb 2012, 17:14 |
|
revolution 10 Feb 2012, 17:21
FASMNOOB wrote: 1. Why does he use this " mov es, ax ; segment register."? FASMNOOB wrote: 2. How would I layout a 3d array. notice he only gave examples for the Code: W3Ary dw (2*3*4) dup ? ;2 dup (3 dup (4 dup (?))) W3Ary2 db 0, 1, 2, 3 db 4, 5, 6, 7 db 8, 9, 10, 11 ; db 20, 21, 22, 23 db 24, 25, 26, 27 db 28, 29, 30, 31 |
|||
10 Feb 2012, 17:21 |
|
FASMNOOB 10 Feb 2012, 17:25
thanks, that solves it.
|
|||
10 Feb 2012, 17:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.