mult_div_example_solns

# mult_div_example_solns - • Divide word variable WHITE by...

This preview shows pages 1–2. Sign up to view the full content.

In class February 13, we did not have time to work through examples for multiplication and division. The slide asked you to write 8086 assembly code to: Multiply BX and CX, store the doubleword product to memory at word variable BLACK Divide word variable WHITE by 38, store quotient to byte variable GRAY RED (WHITE * BLUE) / GOLD ; all variables are bytes RED (WHITE / GOLD) * BLUE ; all variables are bytes My solutions are on the next page. Try to write code for these problems before looking at my solutions. Compare your solutions with mine and ask me any questions that you have.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Assume that all integers are unsigned. Multiply BX and CX, store the doubleword product to memory at word variable BLACK MOV AX, BX ; move one operand into AX MUL CX MOV BLACK, AX ; product is in DX—AX MOV BLACK+2, DX
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • Divide word variable WHITE by 38, store quotient to byte variable GRAY MOV AX, WHITE ; word dividend must be in AX MOV BH, 38 ; no immediate division, so move 38 into a register DIV BH ; places quotient in AL MOV GRAY, AL • RED ← (WHITE * BLUE) / GOLD ; all variables are bytes MOV AL, WHITE MUL AL, BLUE ; places product WHITE * BLUE in AX DIV GOLD ; dividend is already word size, already in AX; DIV places quotient in AL MOV RED, AL • RED ← (WHITE / GOLD) * BLUE ; all variables are bytes MOV AL, WHITE MOV AH, 0 ; need word size dividend, so pad out AH ; would use CBW if data was signed DIV GOLD ; places quotient in AL MUL BLUE ; one operand is already in AL, places product in AX MOV RED, AL ; note that the high order byte is in AH, could do in addition: MOV RED+1, AH...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern