UMBC CMSC 211

UMBC | CSEE


Sets

Sets are a collection of data items, each of which can hold one of two possible values. Forunately, that is binary, which the computer can handle very well. Suppose we want to keep track of which of the 256 interrupts are valid (or implemented) The state would be valid or invalid, so that is binary. There are 8 bits in a byte, so we can store that in 32 bytes, or an array of 32 bytes. (Some people call this a bit array.)

validI DB 32 dup ( 0 )

So if we want to indicate that Interrupt 17 is valid, we can divide by 8, giving is 2 and remainder of 1. So we would want to do something like:

  	mov	bx, OFFSET validI
	add	bx, 2
	or	[bx], 00000010b
  
Yes, that is the long way.
  	mov	bx, OFFSET validI
	or	[bx + 2], 00000010b
  

Then to check to see if it is valid, I could go:

    	mov	bx, OFFSET validI
	and	[bx + 2], 00000010b
  	jz	notValid
	;
	; This is the code for it it is valid.
	;
notValid:	
  
Starting with the 80386, there are instructions to help check to see if the bit is set or clear:

bs bit test
bts bit test and set
btr bit test and reset
btc bit test and complement
These instructions will copy the bit in question to the carry flag, where you can use the jc or jnc instruction. They work with word and doubleword locations.


UMBC | CSEE