| UMBC CMSC 211 Fall 1999 |
The simplest type of shift instruction is to shift zeroes into the vacated positions and to throw away the bits shifted out the other end. This is called a logical shift. The instructions are:
The last bit shifted out is stored in the Carry Flag so that it can be tested. The form is:
The form is:
NOTE: Count is either the number 1 or the cl register.
The last shifts are called rotates. This is a circular shift (which is what they used to be called.) The bit that comes out of the register or memory location on one side goes back in on the other side, with a copy of that bit stored in the Carry Flag.
The form is:
| year - 1900 | bits 9 - 15 (leftmost seven bits) |
| month | bits 5 - 8 (January is 1) |
| day | bits 0 - 4 (rightmost five bits) |
Now we can do the following:
| .MODEL | small | ||
| .STACK | 100h | ||
| YEARMASK | EQU | 1111111000000000B | |
| MONTHMASK | EQU | 0000000111100000B | |
| DAYMASK | EQU | 0000000000011111B | |
| .DATA | |||
| modDate | DW | ? | |
| funnyYear | DW | ? | ; The year is still in bits 9 - 15 |
| funnyMonth | DW | ? | ; The month is still in bits 5 - 8 |
| OKYear | DW | ? | ; The day is in bits 0 - 4 and ; all other bits are set to 0 |
| OKMon | DW | ? | |
| OKDay | DW | ? | |
| .CODE | |||
| example2a | PROC | ||
| mov | ax, @data | ||
| mov | ds, ax | ||
| ; | ... | ; Do something to get the ; modification date | |
| mov | ax, modDate | ||
| and | ax, YEARMASK | ||
| mov | funnyYear, ax | ||
| mov | cl, 9 | ||
| shr | ax, cl | ; Move year to bit 0 | |
| mov | OKYear, ax | ; save the good version | |
| mov | ax, modDate | ||
| and | ax, MONTHMASK | ||
| mov | funnyMonth, ax | ||
| mov | cl, 5 | ||
| shr | ax, cl | ; Move year to bit 0 | |
| mov | OKMonth, ax | ; save the good version | |
| mov | ax, modDate | ||
| and | ax, DAYMASK | ||
| mov | ax, OKDay | ||
| ; At this point, the values ; are not usualable yet | |||
| mov | al,0 | ||
| mov | ah, 4ch | ||
| int | 21h | ||
| example2a | ENDP | ||
| END | example2a | ||