Author Topic: Record and unions  (Read 3848 times)

Magnum

  • Member
  • *****
  • Posts: 2304
Record and unions
« 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.

Code: [Select]
; 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

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Record and unions
« Reply #1 on: January 31, 2013, 02:22:44 PM »
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

  • Member
  • **
  • Posts: 55
Re: Record and unions
« Reply #2 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

Magnum

  • Member
  • *****
  • Posts: 2304
Re: Record and unions
« Reply #3 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
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

goofprog

  • Guest
Re: Record and unions
« Reply #4 on: September 15, 2013, 07:37:59 PM »
I think in TASM language that is a MACRO