flat assembler
Message board for the users of flat assembler.

Index > DOS > segments arithmetic

Author
Thread Post new topic Reply to topic
litwr



Joined: 23 Aug 2005
Posts: 11
Location: Moscow, Russia
litwr 28 Aug 2006, 09:15
The next example shows my problem. It is impossible to use multiplication/division arithmetic with segments address. Crying or Very sad The addition/subtraction arithmetic may be used. Confused I consider this matter as bug...

Code:
format MZ

ENTRY SEG_CODE:START
STACK 2000H
HEAP 0

SEGMENT         SEG_CODE USE16
START:          mov     [X],SEG1*2              ;ERROR!
                mov     [X],SEG1 shl 1          ;ERROR!
                mov     [X],SEG1 shr 1          ;ERROR!!!
                mov     [X],SEG1*10000H + X     ;ERROR! - simple addr calc...
                mov     [X],SEG1 + 10H          ;NO ERROR!!!


SEGMENT         SEG1    USE16
X               DD      0    
Post 28 Aug 2006, 09:15
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 28 Aug 2006, 09:58
it's not a bug, i suggest you to study something about MZ relocations
Post 28 Aug 2006, 09:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
litwr



Joined: 23 Aug 2005
Posts: 11
Location: Moscow, Russia
litwr 01 Sep 2006, 05:05
I want to load full DD (segment:offset) address by one command with 32-bit immediate value. It's easy if I can multiply segment address. So impossibility of such ordinal operation is obvious bug. Sad
Code:
mov [myaddr],segment_addr*10000H+offset    

, myaddr has DD type. I hope that next version of nice FASM will find a way to solve this problem...
Post 01 Sep 2006, 05:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 01 Sep 2006, 08:44
No 16-bit-capable assembler I'm aware of has such feature, since it would be a quite tricky one to detect such very special cases when the shifted relocation placement would do the job.

However you may try to do the trick with a macro (though not a trivial one):
Code:
macro mov dest,src
{
  local pending
  match seg:offs,src
  \{
     local ..ins,L,B
     ..ins:
     virtual at $
       mov dest,dword 0
       L = $-4-..ins 
     end virtual
     repeat L
       virtual at ..ins
         mov dest,dword 0
         load B byte from ..ins+%-1
       end virtual
       db B
     end repeat
     dw offs,seg
     pending equ
  \}
  match =pending,pending
  \{
     mov dest,src
  \}
}

                mov     [X],SEG1:X 
    
Post 01 Sep 2006, 08:44
View user's profile Send private message Visit poster's website Reply with quote
litwr



Joined: 23 Aug 2005
Posts: 11
Location: Moscow, Russia
litwr 01 Sep 2006, 09:00
Wow!!! Shocked But anyway, thank you very much for this example. I only have to note that FASM is 32-bit assembler. I remember odd things with famous Borland TASM - it had always generated 3 bytes JMP instruction (it didn't want to choice 2 bytes code in the appropriate cases), etc... These TASM BUGS may also be avoided by macros. Wink
Post 01 Sep 2006, 09:00
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 01 Sep 2006, 09:05
litwr wrote:
I only have to note that FASM is 32-bit assembler.

What do you mean? Well, it is written itself in a 32-bit code, but as for the capabilities - it's capable of outputting the 16-bit, 32-bit and 64-bit code.
Post 01 Sep 2006, 09:05
View user's profile Send private message Visit poster's website Reply with quote
litwr



Joined: 23 Aug 2005
Posts: 11
Location: Moscow, Russia
litwr 01 Sep 2006, 10:13
Maybe other old assemblers can't do requested task but FASM is new, rapidly developed, and 32-bit code oriented. Very Happy My example code directly uses 32-bit arithmetic. Such cases are easily separated from 16-bit segment arithmetic where multiplication is not good choice. I can insist that if expression with segment address is a 32-bit value then the segment address must be considered as ordinary number with type of word.
There is another way. It may be special function converted segment address to number.
Old good TASM also couldnot work with far JUMPs and CALLs for some IMPORTANT reasons. Razz I've just showed logically correct assembler command and I can expect that it will do its job. Exclamation The mentioned IMPORTANT scholastic reasons are out of my scope.
Post 01 Sep 2006, 10:13
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 01 Sep 2006, 10:18
I said "the 16-bit capable" assemblers, which doesn't mean the same as "old". And your example code is not just a simple 32-bit arithmetic, since it involves the relocatable values, which give are pretty limited possibilities of calculations at all, no matter how "modern" the assembler is. The relocatable values cannot be considered an ordinary numbers - this is imposed by the output format (MZ in this case), and cannot be altered (I suggest following the vid's suggestion to read more on relocatable formats).
Post 01 Sep 2006, 10:18
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 01 Sep 2006, 14:06
i must repeat myself: i suggest you to study something about MZ relocations

... before arguing
Post 01 Sep 2006, 14:06
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
litwr



Joined: 23 Aug 2005
Posts: 11
Location: Moscow, Russia
litwr 04 Sep 2006, 09:44
Sorry, sorry, sorry... I was wrong. Crying or Very sad Sad I have only to add that keyword to the problem is not "segment relocation" but "OS loader". Thanks to all! Laughing
Post 04 Sep 2006, 09:44
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.