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

Evaluate bandwidth of disk drive, Q. Evaluate Bandwidth of disk drive? ...

Q. Evaluate Bandwidth of disk drive? Bandwidth:  Bandwidth can be measured in bytes per second. Sustained bandwidth is the average data rate at the time of a large transfer w

Define static memories, Define static memories? Memories that consists ...

Define static memories? Memories that consists of circuits capable of retaining their state as long as power is applied is known as static memories

Asembly language programming, Ask question #Minimum Write a program to mask...

Ask question #Minimum Write a program to mask bits D3D2D1D0 and to set bits D5D4 and to invert bits D7D6 of the AX register. 100 words accepted#

Identify the fastest logic gate, Which of the following is the fastest logi...

Which of the following is the fastest logic ECL, TTL, CMOS or LSI ? Ans. The fastest logic is ECL.

Dataset accept changes and data adapter update method, Explain Dataset Acce...

Explain Dataset Accept Changes and Data Adapter Update methods?  Data Adapter Update method Calls the respective INSERT, UPDATE, or DELETE statements for every inserted, update

What are threaded binary trees, What are threaded binary trees? A Threa...

What are threaded binary trees? A Threaded Binary Tree is a binary tree in which each node that does not have a right child has a THREAD (in real sense, a link) to its INORDER

Discuss about os as system software, Discuss about OS as system software? ...

Discuss about OS as system software? OS is a large program or actually a collection of routines that is used to control the sharing of and interaction between various computer

Flowchart, how can we find compound interest through flowchart

how can we find compound interest through flowchart

Explain ones complement operator, One's Complement Operator: ~ The one'...

One's Complement Operator: ~ The one's complement operator, sometimes called the "bitwise complement" or "bitwise NOT" operator, produces the bitwise one's complement of its op

Appropriate problems for ann learning, Appropriate Problems for ANN learnin...

Appropriate Problems for ANN learning: Conversely as we did for decision trees there it's important to know where ANNs are the right representation scheme for such job. Howeve

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