Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Next you will need to write a simple main driver in C. Your main driver should m

ID: 3667287 • Letter: N

Question

Next you will need to write a simple main driver in C. Your main driver should make calls to the show_eax() function. The show_eax() function should first call clearScr() to clear the screen, then convert the value in the eax register to a string, and then call writeScr() to write the string "The value of the EAX register is: " followed by the converted string to the middle of the screen. The functions have the following prototypes:

void show_eax();
void clearScr();

void writeScr(char *string, int row, int col);

You will actually write the show_eax(), clearScr() and writeScr() functions in Intel x86 assembly language. Note that you will need to understand how parameters are passed from C to an assembly language function. I will give simple functions to convert numbers to strings. Those functions are as follows:

int convert_num_h(unsigned int num, char buf[]) {
if (num == 0) {
    return 0;
}
int idx = convert_num_h(num / 10, buf);
buf[idx] = num % 10 + '0';
buf[idx+1] = '';
return idx + 1;
}


void convert_num(unsigned int num, char buf[]) {
if (num == 0) {
    buf[0] = '0';
    buf[1] = '';
} else {
    convert_num_h(num, buf);
}
}

Therefore, your algorithm for show_eax() should look like the following:

eax_msg: .ascii "The value in the EAX register is: "
eax_val: .asciiz "          " /* ten spaces, the max number of digit in an unsigned int /*
show_eax:
    /* set up ebp
       push offset of eax_val onto stack
       push val of eax onto stack
       call the C convert_num function
       clean up stack
       push parameters for writescr onto stack to print eax_msg
       call writescr
       clean up stack */
       ret
      
Your main() driver for your OS should be written in C, and should call the show_eax() function and then enter an infinite while loop.

Explanation / Answer

#include "idt.h"
#include "lgdts.h"
#include "queue.h"
#include "mutex.h"
#include "pcb.h"

void clearScr() ;
void segmentLoads(unint32_t code, unint32_t data, unint32_t stack,
unint32_t video) ;
void lgdtsLoads(gdts_ptrs_t *pgdt) ;
void protectCleared() ;
void writeScr(char *string, int row, int col) ;
void process1();void process2();void process3();void process4();void process5();
void process6();void process7();void process8();void process9();void process10();
int* stackAllocate() ;
int createProcess(unint32_t ds, unint32_t ss, unint32_t topDStack, unint32_t cs, unint32_t procesEntrance) ;

void configPIC();
void initial_IDT();
void arrange();
void lidtsLoads(idts_ptrs_t *pidt) ;
void proceed();

// Program 5 functions
int convert_num_h ( unsigned int num , char buff[] ) ;
void convert_num ( unsigned int num , char buff[] ) ;
void mutexs_initialize(mutexs_t *m);
void unlatch(unint32_t *);

/* Global variables */
int STACK_SIZE=1024 ;
gdts_ptrs_t prgmLgdts ; // pointer 2 ^
gdts_entrance_t lgdts[5] ; // Global descriptor table
int followingStack =0 ;
int arraysStack[10][1024] ;

int timer =0 ;
idts_entrance_t idt[256] ;
idts_ptrs_t myIDT;

// Program 5 Variables
mutexs_t m ;
unint32_t bolt ;
unint32_t globVariabl =0 ;
unint32_t completed =0 ;

int main()
{
clearScr () ;
writeScr ( " Starting OS " , 0 , 0 ) ;
writeScr ( " Setting_up OS descriptors ... " , 1 , 0 ) ;
  
//Set up the GDT
initGDTEntry ( &lgdts[0] , 0 , 0 , 0 , 0 ) ; // NULL
initGDTEntry ( &lgdts[1] , 0 , 640 * 1024 - 1 , 0x9A , 0x40 ) ; // Code
initGDTEntry ( &lgdts[2] , 0 , 640 * 1024 - 1 , 0x92 , 0x40 ) ; // Data
initGDTEntry ( &lgdts[3] , 0 , 640 * 1024 - 1 , 0x92 , 0x40 ) ; // Stack
initGDTEntry(&lgdts[4], 0xB8000, 80*25*2-1, 0x92, 0x40); //Video

prgmLgdts.lim =sizeof ( lgdts ) - 1 ;
prgmLgdts.base =( unint32_t ) lgdts ;

lgdtsLoads ( /* ( gdts_entrance_t* ) */ &prgmLgdts ) ;
  
// Load d segment registers
segmentLoads ( 8 , 16 , 24 , 32 ) ;

// print 2 d screen in protected_mode
protectedWrite ( " done. " , 2 , 28 ) ;
int i ;
int j ;
for ( i =3 ; i < 25 ; i++ )
{
for ( j =0 ; j < 80 ; j++ )
  
   {
protectedWrite ( "*" , i , j ) ;
}
}
protectCleared () ;
protectedWrite ( " Flowing 10 processes. . . " , 0 , 0 ) ;

// initializing d mutex
mutexs_initialize ( &m ) ;

// initializing queue for utilization
queues.head=0 ;
queues.tail=9 ;

// configuring IDT
initial_IDT () ;
  
// temparory hold on ISR
asm ( " cli " ) ;

// configuring PIC
configPIC () ;
int *s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE ) , (unint32_t) 8 , (unint32_t) process1 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE ) , (unint32_t) 8 , (unint32_t) process2 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process3 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process4 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process5 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process6 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process7 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process8 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process9 ) ;

s= stackAllocate () ;
createProcess ( (unint32_t) 16 , (unint32_t) 24 , (unint32_t) ( s + STACK_SIZE) , (unint32_t) 8 , (unint32_t) process10 ) ;

proceed () ;
while ( 1 ) ;
}

void clearScr ()
{
int i, j;
for(i = 0; i < 25; i++)
{
for(j = 0; j < 80; j++)
{
writeScr(" ", i, j);
}
}
}


void protectCleared()
{
int i, j;
for(i = 0; i < 25; i++)
{
for(j = 0; j < 80; j++)
{
protectedWrite(" ", i, j);
}
}
}

//Processes
void process1()
{
int i;
char buffer[100] = "process1 Number is: ";
for ( i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 5, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process2()
{
int i;
char buffer[100] = "process2 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 6, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process3()
{
int i;
char buffer[100] = "process3 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 7, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process4()
{
int i;
char buffer[100] = "process4 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 8, 0);
mutexs_unlatch(&m);
}
while (1);

}

void process5()
{
int i;
char buffer[100] = "process5 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 9, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process6()
{
int i;
char buffer[100] = "process6 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 10, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process7()
{
int i;
char buffer[100] = "process7 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 11, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process8()
{
int i;
char buffer[100] = "process8 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 12, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process9()
{
int i;
char buffer[100] = "process9 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+14);
protectedWrite(buffer, 13, 0);
mutexs_unlatch(&m);
}
while (1);
}

void process10()
{
int i;
char buffer[100] = "process10 Number is: ";
for (i = 0; i < 100000; i++) {
mutexs_latch(&m);
int myVar = globVariabl;
myVar++;
globVariabl = myVar;

if (i == 99999) {
completed++;
}
convert_num(globVariabl, buffer+15);
protectedWrite(buffer, 14, 0);
mutexs_unlatch(&m);
}
while (1);
}

int* stackAllocate()
{
followingStack++;
return arraysStack[followingStack-1];
}

int createProcess ( unint32_t ds , unint32_t ss , unint32_t topDStack , unint32_t cs , unint32_t procesEntrance )
{
unint32_t *st= (unint32_t * ) topDStack ;
st-- ;
*st =0 ;
st-- ;
*st =cs ;
st-- ;
*st= procesEntrance ;
st-- ;
*st=0 ; // ebp
st--;
*st=0 ; //esp
st-- ;
*st=0; // edi
st-- ;
*st=0 ; // esi
st-- ;
*st=0 ; // edx
st-- ;
*st=0 ; // ecx
st-- ;
*st=0 ; // ebx
st-- ;
*st=0 ; // eax
st-- ;
*st=ds ; // ds
st-- ;
*st=ds ; // es
st-- ;
*st=ds ; // fs
st-- ;
*st=ds ; // gs

pcb_t *pcb=allocatePCB () ;
pcb -> ss =ss ;
pcb -> esp=(unint32_t)st ;
enqueue ( pcb ) ; // add pointer 2 queue.
}

void initial_IDT(){
int i = 0;
while ( i < 32 )
{
initIDTEntry ( &idt[i] , (unint32_t) defaultIntHand , 8 , 0x8e ) ;
i++ ;
}

initIDTEntry ( &idt[32] , (unint32_t) arrange , 8 , 0x8e ) ;

i=33 ;
while ( i < 256 )
{
initIDTEntry ( &idt[i] , 0 , 8 , 0 ) ;
i++ ;
}

myIDT.limit= sizeof ( idt ) - 1 ;
myIDT.base= (unint32_t ) idt ;
lidtsLoads ( &myIDT ) ;
}

void configPIC() {
outport ( 0x20 , 0x11 ) ;
outport ( 0xA0 , 0x11 ) ;
outport ( 0x21 , 0x20 ) ;
outport ( 0xA1 , 0x28 ) ;
outport ( 0x21 , 0x04 ) ;
outport ( 0xA1 , 0x02 ) ;
outport ( 0x21 , 0x01 ) ;
outport ( 0xA1 , 0x01 ) ;
outport ( 0x21 , 0x0 ) ;
outport ( 0xA1 , 0x0 ) ;
outport ( 0x21 , 0xfe ) ;
outport ( 0xa1 , 0xff ) ;
}

int convert_num_h(unsigned int num, char buffer[]) {
if(num == 0) {
return 0;
}
int idx = convert_num_h(num / 10, buffer);
buffer[idx] = num % 10 + '0';
buffer[idx+1] = '';
return idx + 1;
}

void convert_num(unsigned int num, char buffer[]) {
if (num == 0) {
buffer[0] = '0';
buffer[1] = '';
} else {
convert_num_h(num, buffer);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote