Question

Write a Hack Assembly Language program to calculate the quotient from a division operation. The values...

Write a Hack Assembly Language program to calculate the quotient from a division operation. The values of dividend a and divisor b are stored in RAM[0] (R0) and RAM[1] (R1), respectively. The dividend a is a non-negative integer, and the divisor b is a positive integer. Store the quotient in RAM[2] (R2). Ignore the remainder.

Example: if you are given two numbers 15 and 4 as dividend a (R0) and divisor b (R1), respectively, the answer will be 3 stored in R2.

test cases:

| RAM[0] | RAM[1] | RAM[2] |
| 1 | 1 | 1 |
| 2 | 2 | 1 |
| 0 | 2 | 0 |

Homework Answers

Answer #1

// Storing R0 value into a new variable a

R0
X = Y // X= R0
a
Y = X // a = R0

// Storing R1 value into a new variable b

R1
X = Y // X = R1
b
Y= X // b = R1

// Initializing R2 as 0
0
X = Z // X = 0
R2
Y = X // R2 = 0


(NOTZERO)
a
X = Y // X = a
b
X = X - Y // X = a - b

END
X;JLT // (a-b) < 0 go to END

ZERO
X;JEQ // If (a - b == 0) go to ZERO


R2
Y = Y + 1 // R2 = R2 + 1

b
X = Y // X = b
a
Y = Y - X // a = a - b

NOTZERO // Going back to start of loop
0;JMP

(ZERO)
R2
Y = Y + 1 // R2 = R2 + 1
(END)
END
0;JMP

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a simple ARM assembly language program that finds the mean (as an integer) of all...
Write a simple ARM assembly language program that finds the mean (as an integer) of all values of an integer array. When your program starts, you should assume that r0 contains the address of the array and r1 contains the number of integers in the array. When you program finishes, the mean should be stored in r2. You may use other registers as stack registers.
VII. After execution of the following instructions what value will be in register r2? Trace the...
VII. After execution of the following instructions what value will be in register r2? Trace the program and write the value of the registers at each line to receive full credit. LDR r12, =0xA4000000 LDR r0, =0x2D STR r0, [r12, #-4]! LDR r0, =0x5E STR r0, [r12, #-4]! LDR r0, =0xD5 STR r0, [r12, #-4]! LDMIA r12!, {r0-r2} SUB r2, #0x68 VIII. Write a simple ARM assembly program to divide a 32 bit positive number stored in r0 by a...
Write an ARM assembly language program that counts the number of 1’s for any value in...
Write an ARM assembly language program that counts the number of 1’s for any value in R0. The program must assemble/compile in KEIL and must be able to run in the KEIL simulator. Generally, R0 may contain any value, but for purpose of this exercise, you may move 0x2345ABCD into R0. The number in R0 does not need be preserved. You may use any other registers as you need. The result, total count of 1’s in R0, should be in...
Write a program in ARM assembly language that copies each element of array A to consecutive...
Write a program in ARM assembly language that copies each element of array A to consecutive fourth elements of array B, i.e., A[0] to B[0], A[1] to B[3], A[2] to B[7], etc. The array A is 12 elements long, and each element is a number that is 32 bits (1 word) wide. Assume the base address of array A is in register R2, and the base address of array B is in R3.
EMBEDDED: Write a program in ARM assembly language that copies each element of array A to...
EMBEDDED: Write a program in ARM assembly language that copies each element of array A to consecutive fourth elements of array B, i.e., A[0] to B[0], A[1] to B[3], A[2] to B[7], etc. The array A is 12 elements long, and each element is a number that is 32 bits (1 word) wide. Assume the base address of array A is in register R2, and the base address of array B is in R3.
if statement translation Using ARM assembly language, initialize the variables a, b, and c to consecutive...
if statement translation Using ARM assembly language, initialize the variables a, b, and c to consecutive integers starting at 1. Create your code so that a is in R0, b is in R1, and c is in R2. Build the following if statements, using the ARM Cortex-M0 instructions, in sequence in your code. Please put both if statement implementations in one file. Send me your .s file for grading. if a == 1 b = b * 4 + 2...
Write a program in assembly language for x86 Processors, that uses a loop to calculate the...
Write a program in assembly language for x86 Processors, that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n -1) + Fib(n - 2)
Using Windows 32 framework , write an assembly language program; Write a recursive procedure to find...
Using Windows 32 framework , write an assembly language program; Write a recursive procedure to find the greatest common divisor of two non negative numbers. You should use Euclidean algorithm and this is typically discussed in CSC 230. Your procedure: ❼ Needs to follow cdecl protocol. ❼ Needs to take two parameters. ❼ Should return -1, if the parameters are negative. ❼ Should return gcd, if the parameters are non negative. Your main procedure should do the followings. ❼ Read...
Write an assembly language instruction to program the 82C55 to get data from port A and...
Write an assembly language instruction to program the 82C55 to get data from port A and send it to port B, if PA=IN, PB=OUT, PC0-PC3=IN, and PC4- PC7=OUT and operating in Mode 0. Use port addresses of 300H-303H for the 82C55 chip.
Write a program in Assembly language that calculates the maximum and minimum of 10 numbers stored...
Write a program in Assembly language that calculates the maximum and minimum of 10 numbers stored in memory and writes them to the memory locations. #using loop num: dw 56, 45, 36, 67, 76, 22, 89, 12, 29, 83 min: dw 0 max: dw 0 I wrote a codem but I got an error when I executed it [ORG 0x0100] jmp start num: dw 56, 45, 36, 67, 76, 22, 89, 12, 29, 83 min: dw 0 max: dw 0...