Example on public divisor, Computer Engineering

Assignment Help:

Q. Example on PUBLIC DIVISOR?

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:  

; PROGRAM MODULE PROCEDURES

 

; 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

; DESTROYS: AX, BX, CX, DX, BP, FLAGS

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.

PROCEDURES   SEGMENT PUBLIC

SMART_DIV PROC FAR

                                 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

EXIT:   RET 

SMART_DIV   ENDP 

PROCEDURES   ENDS 

END 

Discussion: 

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.


Related Discussions:- Example on public divisor

What is elapsed time of computer system, What is elapsed time of computer s...

What is elapsed time of computer system? The total time to implement the total program is known as elapsed time. It is affected by the speed of the processor, the disk and the

Explain about ip access, Explain about IP Access. IP access on the netw...

Explain about IP Access. IP access on the network by: • Intranets onto Virtual IP Networks and • Extranets onto Virtual IP Networks.

Introduction to e-commerce, Have you heard about e-commerce? What place is ...

Have you heard about e-commerce? What place is e-commerce located at? What are e-commerce objectives? When did e-commerce starts? How e-commerce works? Who takes advantages of e-co

Hat are the advantages and disadvantages of hardwired, What are the advanta...

What are the advantages and disadvantages of hardwired and micro programmed control? Advantages of hardwired control i. Operate at high speed ii Each state of this coun

Is strategy - information system, IS strategy - Information System As ...

IS strategy - Information System As an operations manager when attempting to navigate your organisation through the information landscape and make best use of the available sy

Give some examples of malicious data, Give some examples of malicious data....

Give some examples of malicious data.  In May 2002, the Norton Anti-Virus software for Windows operating systems detects about 61000 malicious programs. Some of them are named

What are the end-to-end layers of osi structure, What are the end-to-end la...

What are the end-to-end layers of OSI structure The layers 4-7 of ISO-OSI reference model communicate with peer entities in end systems. There is not any communication with ent

What is the future in mq if i have 2+exp, It speeds execution of distribute...

It speeds execution of distributed applications. It runs on dissimilar platforms. It time independent. No loss for msg delivery i.e. guarantee delivery.

Feature of micro-instruction execution, Q. Feature of micro-instruction exe...

Q. Feature of micro-instruction execution? Feature of micro-instruction execution is micro-instruction sequencing which involves address calculation of next micro-instruction.

Draw the circuit diagram of a Master-Slave J-K flip-flop, Draw the circuit ...

Draw the circuit diagram of a Master-slave J-K flip-flop using NAND gates. What is race around condition? How is it eliminated in a Master-slave J-K flip-flop? Ans. Using NA

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd