News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Record and unions

Started by Magnum, January 31, 2013, 01:59:33 PM

Previous topic - Next topic

Magnum

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

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

MichaelW

Your posted code is a MASM example from the MASM Programmer's Guide.
Well Microsoft, here's another nice mess you've gotten us into.

Rockphorr

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

Magnum

Your right Michael.

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

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

goofprog

I think in TASM language that is a MACRO