The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: Magnum on January 31, 2013, 01:59:33 PM

Title: Record and unions
Post by: Magnum on January 31, 2013, 01:59:33 PM
I ran across this.

Is "record" something specific to Turbo Assember ?

I could not find it in my masm search.

I could not find a way to demonstrate it's use where you can see something displayed.

I was also wondering if unions are still used.


; record1.asm Example of a record
;
.model small, c
.486
.stack

.data

COLOR           RECORD  blink:1, back:3, intense:1, fore:3
message         COLOR   <1, 5, 1, 1>
wblink  EQU     WIDTH blink         ; "wblink"     = 1
wback   EQU     WIDTH back          ; "wback"      = 3
wintens EQU     WIDTH intense       ; "wintens"    = 1
wfore   EQU     WIDTH fore          ; "wfore"      = 3
wcolor  EQU     WIDTH COLOR         ; "wcolor"     = 8

.code

.startup

        mov     ah, message         ; Load initial   1101 1001
        and     ah, NOT MASK back   ; Turn off   AND 1000 1111
                                    ; "back"         ---------
                                    ;                1000 1001
        or      ah, MASK blink      ; Turn on     OR 1000 0000
                                    ; "blink"        ---------
                                    ;                1000 1001
        xor     ah, MASK intense    ; Toggle     XOR 0000 1000
                                    ; "intense"      ---------
                                    ;                1000 0001

        IF      (WIDTH COLOR) GT 8  ; If color is 16 bit, load
        mov     ax, message         ;   into 16-bit register
        ELSE                        ; else
        mov     al, message         ;   load into low 8-bit register
        xor     ah, ah              ;   and clear high 8-bits
        ENDIF   

.exit
end

Title: Re: Record and unions
Post by: MichaelW on January 31, 2013, 02:22:44 PM
Your posted code is a MASM example from the MASM Programmer's Guide.
Title: Re: Record and unions
Post by: Rockphorr on February 01, 2013, 03:00:15 AM
for short -- RECORD is mnemonic name of bit mask
it uses with binary data when you declare every bit

refer kip irvin 4 edition

using of unions is sign of dirty(draft) design of structure decomposition


COLOR           RECORD  blink:1, back:3, intense:1, fore:3

it is defenition bit mask by length in bits 1 bit for blink etc

after you define vars with color type and set values by fields of record

message         COLOR   <1, 5, 1, 1>

if you try
message         COLOR   <1, 9, 1, 1>
you get error cause 9 is above 7 as 3 bits
Title: Re: Record and unions
Post by: Magnum on February 01, 2013, 06:19:22 AM
Your right Michael.

I believe I converted it to tasm form and looked for a practical example of it's use.

Andy
Title: Re: Record and unions
Post by: goofprog on September 15, 2013, 07:37:59 PM
I think in TASM language that is a MACRO