Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with this HW: Neither multiplication nor division are supported by t

ID: 3708000 • Letter: P

Question

Please help with this HW: Neither multiplication nor division are supported by the MSP430 CPU ALU Division: To divide A/B, subtract B from A as many times as possible until the difference is smaller than B. The difference is the residue R and the number of subtractions is the quotient Q Suggestions: Test your understanding by dividing 11/3 by hand using the algorithm above. Translate the description to pseudo code, e.g., WHILE (divisor >dividend) quotient++; remainder - divisor - dividend; divisor remainder; sor dividend; END WHILE Translate the pseudo code to assembly language. Dividing 11/3 with assume A and B are 16-bit words.

Explanation / Answer

Division without using division operator.

while(divisor>=divident){

quotient++;

remainder=divisor-dividend;

divisor=remainder;}

pseudo code in assembly language.

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], 0

lea rdx, [rbp-16]

lea rax, [rbp-12]

mov rsi, rax

mov edi, OFFSET FLAT:.LC0

mov eax, 0

.L3:

mov edx, DWORD PTR [rbp-12]

mov eax, DWORD PTR [rbp-16]

cmp edx, eax

jl .L2

add DWORD PTR [rbp-4], 1

jmp .L3

.L2:

mov edx, DWORD PTR [rbp-12]

mov eax, DWORD PTR [rbp-16]

sub edx, eax

mov eax, edx

mov DWORD PTR [rbp-8], eax

mov eax, DWORD PTR [rbp-8]

mov DWORD PTR [rbp-12], eax

mov eax, 0

leave

ret