A Convenient Method of Working with Structures

A Convenient Method of Working with Structures

There is one convenient method of working with structures and unions that deserves a special mention. It is based on the ASSUME directive. Actually, I make practically no use of this directive in this book. When programming for MS-DOS, this directive is mainly used to inform the assembler that the segment register points to the current segment. However, this directive can be used with more than segment registers. Here is the fragment that illustrates such a technique.

 COMPLEX STRUC             RE   DD ?             IM   DD ?     COMPLEX  ENDS     .     .     .     ; In  data segment     COMP  COMPLEX <0>     ; In  code segment            MOV    EBX, OFFSET COMP            ASSUME EBX:PTR C0MPLEX            MOV    [EBX].RE, 10            MOV    [EBX].IM, 10            ASSUME EBX:NOTHING 

Actually, the MOV [EBX] .RE , 10 command is equivalent to MOV DWORD PTR [EBX] , 10 , and the MOV [EBX].IM , 10 command is equivalent to MOV DWORD PTR [EBX+4] , 10 . You likely will agree that this is very convenient.



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net