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

Explain arithmetic data processing instructions, Q. Explain Arithmetic Data...

Q. Explain Arithmetic Data Processing Instructions? These instructions carry outlogical and arithmetic operations on data. Arithmetic: The four fundamental operations are

What are the characteristics of sram, What are the characteristics of SRAM?...

What are the characteristics of SRAM? SRAM are fast They are volatile They are of high cost Less density

Find resolution and output voltage of D/A convertor, A 6-bit R-2R ladder D/...

A 6-bit R-2R ladder D/A converter has a reference voltage of 6.5V. It meets standard linearity.Find (i) The Resolution in Percent. (ii) The output voltage for the word 011100.

Electrically erasable programmable read only memory- EEPROM, Electrically e...

Electrically erasable programmable read only memory (EEPROM) An EEPROM is a special type of PROM which can be erased by exposing it to an electrical charge. Like other kinds of

Define interrupts, Interrupts are signals which cause the CPU to suspend th...

Interrupts are signals which cause the CPU to suspend the currently executing program and transfer to a special program known as an interrupt handler. Interrupt handler determines

Determine flip-flops that are required for mod–16 counter, How many Flip-Fl...

How many Flip-Flops are required for mod-16 counter? Ans. 4 flip-flops is required for Mod-16 Counter. For Mod-m Counter, we require N flip-flops where N is selected to be the

Explain time complexity in parallel algorithms, Q. Explain Time Complexity ...

Q. Explain Time Complexity in Parallel algorithms? As it takes place nearly everyone who implement algorithms wish to know how much of an individual resource (for example time

Masters and slaves, The devices on the I2C bus are either masters or slaves...

The devices on the I2C bus are either masters or slaves. The master is the device that is responsible for driving the SCL clock line, while the slaves are the devices that respond

Define virtual memory, Normal 0 false false false EN-IN...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

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