Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Lab 8 – 60-266-implement binary multiplication using arithmetic shift and add operations using assembly

OBJECTIVES:
i) Understand binary multiplication.
ii) To learn to implement binary multiplication using arithmetic shift and add operations.
iii) To learn to access and manipulate bits using various shift/rotate operations

Problem: a) Multiply a 16-bit unsigned integer (03B2 h) by 12 using arithmetic shift and add operations. The result should be in register ax.
b) Move the most significant 4 bits of ax into the least significant 4 bits of bx. The most significant 4 bits of bx as well as the contents of ax should remain unchanged.

Hints:

• Multiplying a number by 2n is equivalent to shifting it to the left n times.
• 12 = 8 + 4 = 23 + 22
• Not discussed in class: The SHLD instruction can be used to perform a shift operation without modifying the source.
o Students can use SHL however.

Answer:

INCLUDE Irvine32.inc

.code

main PROC

;  Part a)
	mov bx, 03b2h	; Initialize bx to the value
			; to be multiplied

	call dumpregs 	; Display the content of regs

	shl bx, 3	; shift bl to the left 3 times.
			; Result of this operation is
			; equivalant to the value
			; of bx multiplied by 2^3.

	mov ax, bx	; Save bx for future use
	call dumpregs	; display the content of regs

	mov bx, 03b2h	; Initialize bx to the value
			; of the multiplicand

	call dumpregs	; display the content of regs

	shl bx, 2	; shift bl to the left 2 times.
			; Result of this operation is
			; equivalant to the value
			; of bx multiplied by 2^2.
	call dumpregs	; display the content of regs

	add ax, bx	; Add the value of bx to ax. Now, ax
			; contains the result of the multiplication.
			; for part (a)
	call dumpregs	; display the content of regs


; Part b)
	mov bx, 3467h 	; For part (b), re-initialize
			; the value of bx just to test
			; that the move operation is working
			; properly.
	call dumpregs	; display the content of regs

	shr bx, 4	; Shift bx to the right so that after
			; the shld operation, the content of the
			; 12 most significant bits of bx remains same.
	call dumpregs	; display the content of regs

	shld bx, ax, 4	; This operation shifts bx to the left
			; by 4 bits, then replaces the least 4
			; significant 4 bits of bx by the most
			; significant 4 bits of ax
	call dumpregs	; display the content of regs

	exit
main ENDP
END main

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!