Posts

Showing posts from June, 2012

Simple Boot Loader in Assembly

Terminal Commands: nasm boot1.asm -f bin -o boot1.bin dd if=boot1.bin bs=512 of=myhd.img qemu myhd.img Help for boot1.asm: 'INT 0x10' is a BIOS video interrupt. All video related calls are made through this interrupt. To use this interrupt, we need to set the values of some registers as follows.     AL => With ASCII value of character to display     AH => With 0x0E ;           Teletype mode (This will tell bios that we want to print one character on screen)     BL => With Text Attribute (This will be the fore ground and background color             of character to be displayed. 0x07 in our case.)     BH => With Page Number (0x00 for most of the cases)     Once all the registers are filled with appropriate values, we can call interrupt. Implementation in Assembly [BITS 16]                        ;Tells the assembler that its a 16 bit code [ORG 0x7c00]                 ;Origin, tell the assembler that where the code will                        

Posix Thread example

Get a file name from the command line to the main function and create that file. When SIGPWR is received, each thread should write the following line to the created file. The sum from ``low'' to ``i'' is ``myresult''. Also in the main function, before the threads are created, print the process id of the parent process so that you can send SIGPWR to it using the ``kill'' function from another terminal. Implementation in C #include <stdio.h> #include <pthread.h> #include <signal.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #define ARRAYSIZE 1000 #define THREADS 10 #define TRUE 1 #define FALSE 0 void *slave(void *myid); void pwrhandler(int signal); //Signal handling function for PWR signal /* shared data */ int data[ARRAYSIZE]; /* Array of numbers to sum */ int sum = 0; pthread_mutex_t mutex; /* mutually exclusive lock variable */ int wsize;          /* size of work for e