Procedure which divides a 32-bit number by a 16-bit number, Computer Engineering

Assignment Help:

Write a procedure which divides a 32-bit number by a 16-bit number. The procedure must be general which is it's defined in one module and can be called from another assembly module.

; REGISTERS   : Uses CS, DS, SS, AX, SP, BX, CX

; PROCEDURES: Far Procedure SMART_DIV

DATA_SEG SEGMENT   WORD PUBLIC

     DIVIDEND DW 2345h, 89AB; Dividend = 

    ; 89AB2345H

     DIVISOR DW 5678H; 16-bit divisor

     MESSAGE DB 'INVALID DIVIDE', '$'

DATA_SEG ENDS    

 

MORE_DATA   SEGMENT     WORD

                                 QUOTIENT   DW   2 DUP (0)

                                 REMAINDER   DW      0 

MORE_DATA ENDS

STACK_SEG   SEGMENT   STACK

                                 DW   100 DUP (0); Stack of 100 words

                                 TOP - STACK   LABEL WORD; top of stack pointer

STACK_SEG   ENDS

PUBLIC       DIVISOR

PROCEDURES SEGMENT   PUBLIC                    ; SMART_DIVis declared as an

EXTRN SMART_DIV: FAR                                    ; external label in procedure 

                                                                                    ; Segment of type FAR

PROCEDURES ENDS

; declare the code segment as PUBLIC so that it can be merged with other PUBLIC

; Segments

CODE_SEG SEGMENT WORD   PUBLIC

            ASSUME CS: CODE, DS: DATA_SEG, SS: STACK SEG

            START:  MOV AX, DATA_SEG; Initialize data segment

            MOV DS, AX   ; using AX register

            MOV AX, STACK_SEG   ; Initialize stack segment

            MOV SS, AX; using AX register

            MOV SP, OFFSET TOP_STACK; Initialize stack pointer

            MOV AX, DIVIDEND   ; Load low word of

                                                ; Dividend

            MOV   DX DIVIDEND + 2; Load high word of

                                                ; Dividend

            MOV CX, DIVISOR   ; Load divisor

            CALL SMART_DIV   

; This procedure returns Quotient in the DX: AX pair and Remainder in CX register. 

; Carry bit is set if result is invalid.

                                 JNC SAVE_ALL; IF carry = 0, result valid

                                 JMP STOP          ; ELSE carry set, don't

                                                             ; save result

                                 ASSUME DS: MORE_DATA   ; Change data segment

SAVE_ALL:  PUSH DS   ; Save old DS 

MOV BX, MORE_DATA          ; Load new data segment

MOV DS, BX                              ; register

MOV QUOTIENT, AX              ; Store low word of

                                                     ; Quotient

MOV QUOTIENT + 2, DX   ; Store high word of

                                                     ; Quotient

MOV REMAINDER, CX   ; Store remainder

ASSUME DS: DATA_SEG  

POP   DS; Restore initial DS

JMP ENDING

STOP:                       MOV DL, OFFSET MESSAGE

                                 MOV AX, AH 09H

                                 INT   21H  

ENDING:   NOP

CODE_SEG ENDS

                                 END START


Related Discussions:- Procedure which divides a 32-bit number by a 16-bit number

Self-perception, Mr. X seems to view himself in positive terms (MMPI-2: Ho=...

Mr. X seems to view himself in positive terms (MMPI-2: Ho=38) as a well-functioning person who is capable of dealing with his life and personal challenges (MMPI-2: LSE=41, TRT=39),

What is dots per inch, Q. What is Dots per Inch? DPI (Dots per Inch) is...

Q. What is Dots per Inch? DPI (Dots per Inch) is a measure for actual sharpness of onscreen image. This relies on both the resolution and size of the image. Practical experienc

Explain briefly the function of layers, Explain briefly the function of dif...

Explain briefly the function of different layers which are covered under end to end layer connectivity. Different layer are as follows: 1. Transport Layer:  This is res

Determine about the security methods, Determine about the Security methods ...

Determine about the Security methods Security methods also protect information from accidental or intentional modification, manipulation or destruction. Most security experts o

Explain gray code, Explain Gray Code Ans. Gray Code 1.  Extreme...

Explain Gray Code Ans. Gray Code 1.  Extremely useful code. Also termed as reflected code. 2.  All gray code is different from the preceding and succeeding codes thr

Explain proces of defining the document page title, Q. Explain proces of de...

Q. Explain proces of defining the Document Page Title? Though the document has a file name, notice it's still labelled Untitled Document; that is because it needs an HTML docum

Engineering applications, Engineering Applications A few of the enginee...

Engineering Applications A few of the engineering applications are: Airflow circulation over aircraft machinery, Simulations of simulated ecosystems. Airflow c

Define the term- analysis, Define the term- Analysis The analysis invol...

Define the term- Analysis The analysis involves some or all of the following stages: Fact finding - this is usually done in four ways. Understanding the current syst

What is home banking, Home Banking: E-commerce is used in Home Banking ...

Home Banking: E-commerce is used in Home Banking as single call or single click. Online banking (Internet banking) is a term used for performing transactions, payments etc. ove

Determine the implementation of jit inventory system, Discuss in detail the...

Discuss in detail the features, benefits and implementation of JIT inventory system. JIT - Just in Time inventory systems - meaning, origin, need for JIT, benefits, Use of JIT

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