Example on public divisor, Computer Engineering


Linker appends all segments having the same name and PUBLIC directive with segment name into one segment. Their contents are pulled together in consecutive memory locations.

The subsequent statement to be noted is PUBLIC DIVISOR. It tells the assembler and linker that this variable can be legally accessed by other assembly modules. Whereas EXTRN SMART_DIV: FAR conveys the assembler that this module will access a label or a procedure of type FAR in some assembly module. Please also note that EXTRN definition is enclosed within the PROCEDURES ENDS andPROCEDURES SEGMENT PUBLIC to tell the assembler and linker that procedure SMART_DIV is located within the segment PROCEDURES and all such PROCEDURES segments are required to be combined in one. Let's now define the PROCEDURE module:  



; INPUT                      : Dividend - low word in AX, high word in DX, Divisor in CX

; OUTPUT                  : Quotient - low word in AX, high word in DX. Remainder in CX

; Carry                         - carry flag is set if try to divide by zero


DATA_SEG SEGMENT   PUBLIC; this block tells the assembler that

EXTRN DIVISOR: WORD                          ; the divisor is a word variable and is

DATA_SEG   ENDS                         ; external to this procedure. It would be 

                                                            ; found in segment named DATA_SEG

PUBLIC SMART_DIV                     ; SMART_DIV is available to

                                                            ; Other modules. It is now being defined 

                                                            ; In PROCEDURES SEGMENT.



                                 ASSUME CS: PROCEDURES, DS: DATA_SEG

                                 CMP DIVISOR, 0; this is just to demonstrate the use of 

                                                                        ; External variable, otherwise we can 

                                                                        ; Check it through CX register which

                                                                        ; contains the divisor.

JE        ERROR_EXIT   ; IF divisor = 0, exit procedure

MOV  BX, AX   ; Save low order of dividend

MOV  AX, DX; Position high word for 1st divide

MOV  DX, 0000h; Zero DX

DIV     CX; DX: AX/CX, quotient in AX,

                                 ; Remainder in DX

MOV BP, AX                  ; transfer high order of final result to BP

MOV AX, BX                 ; Get back low order of dividend. Note 

                                         ; DX contains remainder so DX: AX is 

                                         ; The actual number

DIV CX; DX: AX/CX, quotient in AX,

                                         ; 2nd remainder that is final remainder 

                                         ; in DX

MOV CX, DX                 ; Pass final remainder in CX

MOV DX, BP                  ; Pass high order of quotient in DX

                                         ; AX contains lower word of quotient

CLC                                 ; Clear carry to indicate valid result

JMP EXIT                        ; Finished


ERROR_EXIT: STC   ; Set carry to indicate divide by zero






Procedure accesses the data item named DIVISOR that is defined in the main consequently the statement EXTRN DIVISOR: WORD is essential for informing assembler that this data name is found in some other segment. Data-type is defined to be of word type. Please consider that DIVISOR is enclosed in same segment name as that of main which is DATA_SEG and procedure is in a PUBLIC segment.

Posted Date: 8/1/2013 3:40:51 AM | Location : United States

Related Discussions:- Example on public divisor, Assignment Help, Ask Question on Example on public divisor, Get Answer, Expert's Help, Example on public divisor Discussions

Write discussion on Example on public divisor
Your posts are moderated
Related Questions
As we know how packets travel from one computer to another over the Internet. However what's in-between? Actually what makes up the Internet infrastructure or backbone? Fi

What is index register? In index mode the effective address of the operand is formed by adding a constant value to the contents of a register. The register used might be either

The advantages of specifying parameters during instantiation method are: -  All values to all the parameters do not need to be specified. Only those parameters that are assigne

Throughput of a system is? Ans. "Throughput" of a system is no. of programs processed by this per unit time.

Overclocking is the process of making a computer or component operate faster than the clock frequency particular by the manufacturer by modifying system parameters. One of the most

The output of a logic gate is 1 when all its inputs are at logic 0. The gate is either ? Ans. When all inputs of logic gate at logic 0 and output is 0. The gate is either a NOR

Proof by Contradiction: Now for forward chaining and backward chaining both have drawbacks. But another approach is to think about proving theorems by contradiction. So we can

Translate the following sentences into predicate logic, using identity (=). a. Everyone was drunk except John. b. Christine rides a bike, but everyone else drives a car. c

This project is aimed at developing a web-based and central recruitment Process system. this web site is for Fresher candidates who graduated. Some features of this system will be

What is an interface and what is an abstract class? Please, expand by examples of using both. Explain why.   In a interface class, all methods are abstract without execution w