;This program demonstrates packing and unpacking data;
;Each data item (really, a record) is defined as follows:
;
;               1111110000000000
;               5432109876543210
;               g     sc a
;               p     el g
;               a     xa e
;                      s
;                      s
;
numstu  equ    100
                jmp     start
; What is missing is a practical way of filling up the array!
;
stu     dw   numstu dup (0)
start:  mov     si, 0           ;offset into array of student records
lp:     mov     ax, stu[si]     ;get next student record
;
;       first, UNpack the data, leaving it in a register by itself
;
        mov     bx, ax          ;make a copy of the record
; Mask out the class data
        and     ax, 0000000110000000B  ;mask off class
        mov     cl, 7                  ;move class into position
        shr     ax, cl                 ;class is now a number 0 - 3
;
;  NOW work with the data
        add     ax, 1                   ;increase class by one year
        cmp     ax, 3
        jbe     okclass
        mov     ax, 3                   ;can't be greater than senior
;
;  Now done with processing info, REPACK it!
;
okclass: mov    cl, 7                   ;reposition the class data
        shl     ax, cl                  ;class is now in the right position
        and     bx, 1111111001111111B    ;save all BUT the class
        or      ax, bx                  ;PACK the data together
        mov     stu [si], ax

        add     si, 2
        cmp     si, numstu*2
        jbe     lp

        int     20h
        end