Professional Documents
Culture Documents
Assembly
Padding disabled
Structure: Bit Fields
Struct{
unsigned char ea:1;
unsigned char oct:3;
unsigned char hex:4;
};
7 0
Structure: Nested
Struct{
char name[10];
struct {
int dd;
char mon[4];
int year;
}dob ;
}x;
x.dob.year=2004;
23 21 16
11 8
7 3 0
Union: Nested
Union{
WREG word;
BREG byte;
}x;
x.byte.al=2;
x.word.ax=1234;
15 8
7 0
Linked List
• A chain for data structure to maintain various
information we need at the run time particularly
• Types:
– Singly
– Doubly
– Circular
– Doubly Circular
Linked List
• Development is based on self referenced
structure.
struct slist
{
Int info;
struct slist *next;
};
• A code to be Implemented
– Creation
– Deletion
– Traversing and printing
– Searching
Stacks and Queues
• Stacks and queues are two very common and
popular data structures.
• Similarly, every new plate taken off the stack is also from the top
of the stack.
Stacks and Queues
• There are several applications where stack can be put to use.
•The first subset contains a single element called the root of the
tree.
•The other two subsets are themselves binary trees, called the
left and right subtrees of the original tree.
#define CHARSIZE 8
#define MASK(y) ( 1 << y % CHARSIZE )
#define BITSLOT(y) ( y / CHARSIZE )
#define SET( x, y) ( x[BITSLOT(y)] |= MASK(y) )
#define CLEAR(x, y) ( x[BITSLOT(y)] &= ~MASK(y) )
#define TEST(x, y) ( x[BITSLOT(y)] & MASK(y) )
#define NUMSLOTS(n) ((n + CHARSIZE - 1) / CHARSIZE)
Bit Arrays
Using these macros we can declare an array of 50 bits be saying,
char arr[NUMSLOTS(50)] ;
To set the 20th bit we can say,
SET ( arr, 20 ) ;
And if we are to test the status of 40th bit we may say,
if ( TEST ( arr, 40 ) )
Using bit arrays often results into saving a lot of precious memory.
– This session explains why gotchas are an inherent part of C and C++.
Types of Gotchas
• Undefined behavior :
• Unspecified behavior:
In a call such as f(i++, j++), the C standard doesn’t tell you whether the
program will increment i before or after incrementing j, but it does tell
you that both i and j will be incremented before the program arrives at f.
Precedence vs. Evaluation Order
#include <conio.h>
void main( ) printf ( "addition result = %d\n", result );
{ _asm {
int result ; mov ax, 10
clrscr( ) ; mov bx, 4
asm mov ax, 5 sub ax, bx
asm mov bx, 7 mov result, ax
asm add ax, bx printf ( "Subtraction result = %d\n", result ) ;
asm mov result, ax }
Inline Assembly
int num;
_asm{
cli
mov eax,num
add eax,0x1234
sti ;
}
………….
Accessing Hardware
To Do
– Understand the 16 bit layout
– Dos memory map
– Accessing external Segments
• Far
• huge
– A reset code
– A security code
– Screen handling
– Checking memory parameters
– Accessing keyboard
The system memory layout
10000H
Reserved for ROM BIOS
E0000H
Reserved for Installable ROM
C0000H Video Buffer
A0000H
TP of DOS
User program and data
Resident Portion of DOS
00500H DATA AREA ROM BIOS BASIC
DATA AREA FOR ROM
00400H IVT
00000H
Some Address to look at