InterviewSolution
| 1. |
How Do I Write Code That Reads Data At Memory Location Specified By Segment And Offset? |
|
Answer» Use peekb( ) function. This function returns byte(s) read from specific segment and offset locations in MEMORY. The following program illustrates use of this function. In this program from VDU memory we have read CHARACTERS and its attributes of the first row. The information STORED in file is then further read and displayed USING peek( ) function. #include #include main( ) { char far *scr = 0xB8000000 ; FILE *fp ; int offset ; char ch ; if ( ( fp = fopen ( scr.dat, wb ) ) == NULL ) { printf ( Unable to OPEN file ) ; exit( ) ; } // reads and writes to file for ( offset = 0 ; offset < 160 ; offset++ ) fprintf ( fp, %c, peekb ( scr, offset ) ) ; fclose ( fp ) ; if ( ( fp = fopen ( scr.dat, rb ) ) == NULL ) { printf ( Unable to open file ) ; exit( ) ; } // reads and writes to file for ( offset = 0 ; offset < 160 ; offset++ ) { fscanf ( fp, %c, &ch ) ; printf ( %c, ch ) ; } fclose ( fp ) ; } Use peekb( ) function. This function returns byte(s) read from specific segment and offset locations in memory. The following program illustrates use of this function. In this program from VDU memory we have read characters and its attributes of the first row. The information stored in file is then further read and displayed using peek( ) function. #include #include main( ) { char far *scr = 0xB8000000 ; FILE *fp ; int offset ; char ch ; if ( ( fp = fopen ( scr.dat, wb ) ) == NULL ) { printf ( Unable to open file ) ; exit( ) ; } // reads and writes to file for ( offset = 0 ; offset < 160 ; offset++ ) fprintf ( fp, %c, peekb ( scr, offset ) ) ; fclose ( fp ) ; if ( ( fp = fopen ( scr.dat, rb ) ) == NULL ) { printf ( Unable to open file ) ; exit( ) ; } // reads and writes to file for ( offset = 0 ; offset < 160 ; offset++ ) { fscanf ( fp, %c, &ch ) ; printf ( %c, ch ) ; } fclose ( fp ) ; } |
|