Embedded C interview Questions - How to initialize the processor ?

Embedded C interview questions

How to initialize the processor?

The following example shows how to initialize a processor here the example of 80187 is taken.

$mod186

name example_80C187_init

;

; FUNCTION: This function initializes the 80C187 numeric

; co-processor.

;

; SYNTAX: extern unsigned char far 187_init (void);

;

; INPUTS: None

;

; OUTPUTS: unsigned char - 0000h -> False -> coprocessor not

; Initialized

; ffffh -> True -> coprocessor

; Initialized

; NOTE: Parameters are passed on the stack as required by

; high-level languages.

;

lib_80186 segment public 'code'

assume cs:lib_80186

public _187_init

_187_init proc far

push bp ;save caller's bp

mov bp, sp ;get current top of stack

cli ;disable maskable

;interrupts

fninit ;init 80C187 processor

fnstcw [bp-2] ;get current control word

sti ;enable interrupts

mov ax, [bp-2]

and ax, 0300h ;mask off unwanted control

;bits

cmp ax, 0300h ;PC bits = 11

je Ok ;yes: processor ok

xor ax, ax ;return false (80C187 not

;ok)

pop bp ;restore caller's bp

ret

Ok: and [bp-2], 0fffeh ;unmask possible exceptions fldcw [bp-2]

mov ax,0ffffh ;return true (80C187 ok)

pop bp ;restore caller's bp

ret

_187_init endp

lib_80186 ends

end

No comments:

Post a comment