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

Determine the minimum bandwidth of the system, Data is to be transmitted us...

Data is to be transmitted using a modem at 9600 bps. Determine the minimum bandwidth of the system with the following modulation methods (a) FSK (b) ASK. Use the excess bandwidth f

Explain the daa instruction, Explain the DAA DAA instruction follows th...

Explain the DAA DAA instruction follows the ADC or ADD instruction to adjust the result into a BCD result. DAA instruction functions only with the AL register, this addition sh

What are the various layers of a file system, What are the various layers o...

What are the various layers of a file system? The file system is composed of lots of dissimilar levels. Each level in the design uses the characteristic of the lower levels to

How do you control instructions like branch, How do you control instruction...

How do you control instructions like branch, cause problems in a pipelined processor? Pipelined processor gives the best throughput for sequenced line instruction. In branch in

Advantages & disadvantages of wired-and connection TTL gates, What are adva...

What are advantages and disadvantages of TTL gates design with Wired-AND connection ? Ans. Advantages and disadvantages In this IC added logic is performed with

Discuss the classifications of switching systems, Discuss the classificatio...

Discuss the classifications of switching systems. The categorizations of switching systems are specified in the block diagram given below:

Program in c, addition c program for token separation

addition c program for token separation

Translate assembly language program to machine , A useful exercise in under...

A useful exercise in understanding assembly language and its relation to machine language is to take a short assembly language program and translate it to machine language by hand.

Explain about the view selection problem, Often calculating all the data is...

Often calculating all the data is not possible by aggregations for this reason some of the difficult data problems are solved. In order to verify which data should be solved and me

How to get the column count of a report, How to get the column count of a r...

How to get the column count of a report? SY-LINSZ system variable gives the column count (line size) and SY-LINCT for line count.

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